﻿#include "stdafx.h"
#include "NDGNSS.h"
#include <iostream>
#include <string.h>
#include <cmath>
using namespace std;
CNDGNSS::CNDGNSS(void)
{

	m_second=0.0;
	m_MM_rcood_X=0;
	m_MM_rcood_Y=0;
	m_MM_rcood_Z=0;

	if ((BPC_fil = _fsopen(_T("chafenxinxi.txt"), "ab", _SH_DENYNO)) != NULL)// _SH_DENYNO:Permits read and write access.
	{
		fseek(BPC_fil, 0, SEEK_END);
	}
	m_pFileStream = NULL;
	GenerateLogName();
	//m_logs = CLogger(_T("F:\\MyProgramme\\GIPSforDbgforcopy_GridPR_HB160812_board_3SYS"),LogLevelAll);
	//m_logs = CLogger();
}
CNDGNSS::~CNDGNSS(void)
{
	if (BPC_fil){ fclose(BPC_fil); }

}
/* ecef to local coordinate transfromation matrix ------------------------------
* compute ecef to local coordinate transfromation matrix
* args   : double *pos      I   geodetic position {lat,lon} (rad)
*          double *E        O   ecef to local coord transformation matrix (3x3)
* return : none
* notes  : matirix stored by column-major order (fortran convention)
*-----------------------------------------------------------------------------*/
void CNDGNSS::xyz2enu(const double *pos, double *E)
{
    double sinp=sin(pos[0]),cosp=cos(pos[0]),sinl=sin(pos[1]),cosl=cos(pos[1]);
    
    E[0]=-sinl;      E[3]=cosl;       E[6]=0.0;
    E[1]=-sinp*cosl; E[4]=-sinp*sinl; E[7]=cosp;
    E[2]=cosp*cosl;  E[5]=cosp*sinl;  E[8]=sinp;
}
/* multiply matrix -----------------------------------------------------------*/
void CNDGNSS::matmul(const char *tr, int n, int k, int m, double alpha,
                   const double *A, const double *B, double beta, double *C)
{
    double d;
    int i,j,x,f=tr[0]=='N'?(tr[1]=='N'?1:2):(tr[1]=='N'?3:4);
    
    for (i=0;i<n;i++) for (j=0;j<k;j++) {
        d=0.0;
        switch (f) {
            case 1: for (x=0;x<m;x++) d+=A[i+x*n]*B[x+j*m]; break;
            case 2: for (x=0;x<m;x++) d+=A[i+x*n]*B[j+x*k]; break;
            case 3: for (x=0;x<m;x++) d+=A[x+i*m]*B[x+j*m]; break;
            case 4: for (x=0;x<m;x++) d+=A[x+i*m]*B[j+x*k]; break;
        }
        if (beta==0.0) C[i+j*n]=alpha*d; else C[i+j*n]=alpha*d+beta*C[i+j*n];
    }
}
/* transform ecef vector to local tangental coordinate -------------------------
* transform ecef vector to local tangental coordinate
* args   : double *pos      I   geodetic position {lat,lon} (rad)
*          double *r        I   vector in ecef coordinate {x,y,z}
*          double *e        O   vector in local tangental coordinate {e,n,u}
* return : none
*-----------------------------------------------------------------------------*/
void CNDGNSS::ecef2enu(const double *pos, const double *r, double *e)
{
    double E[9];
    
    xyz2enu(pos,E);
    matmul("NN",3,1,3,1.0,E,r,0.0,e);
}
/* inner product ---------------------------------------------------------------
* inner product of vectors
* args   : double *a,*b     I   vector a,b (n x 1)
*          int    n         I   size of vector a,b
* return : a'*b
*-----------------------------------------------------------------------------*/
double CNDGNSS::dot(const double *a, const double *b, int n)
{
    double c=0.0;
    
    while (--n>=0) c+=a[n]*b[n];
    return c;
}
/* satellite azimuth/elevation angle -------------------------------------------
* compute satellite azimuth/elevation angle
* args   : double *pos      I   geodetic position {lat,lon,h} (rad,m)
*          double *e        I   receiver-to-satellilte unit vevtor (ecef)
*          double *azel     IO  azimuth/elevation {az,el} (rad) (NULL: no output)
*                               (0.0<=azel[0]<2*pi,-pi/2<=azel[1]<=pi/2)
* return : elevation angle (rad)
*-----------------------------------------------------------------------------*/
double CNDGNSS::satazel(const double *pos, const double *e, double *azel)
{
    double az=0.0,el=PI/2.0,enu[3];
    
    if (pos[2]>-RE_WGS84) {
        ecef2enu(pos,e,enu);
        az=dot(enu,enu,2)<1E-12?0.0:atan2(enu[0],enu[1]);
        if (az<0.0) az+=2*PI;
        el=asin(enu[2]);
    }
    if (azel) {azel[0]=az; azel[1]=el;}
    return el;
}
/* transform ecef to geodetic postion ------------------------------------------
* transform ecef position to geodetic position
* args   : double *r        I   ecef position {x,y,z} (m)
*          double *pos      O   geodetic position {lat,lon,h} (rad,m)
* return : none
* notes  : WGS84, ellipsoidal height
*-----------------------------------------------------------------------------*/
void CNDGNSS::ecef2pos(const double *r, double *pos)
{
    double e2=FE_WGS84*(2.0-FE_WGS84),r2=dot(r,r,2),z,zk,v=RE_WGS84,sinp;
    
    for (z=r[2],zk=0.0;fabs(z-zk)>=1E-4;) {
        zk=z;
        sinp=z/sqrt(r2+z*z);
        v=RE_WGS84/sqrt(1.0-e2*sinp*sinp);
        z=r[2]+v*e2*sinp;
    }
    pos[0]=r2>1E-12?atan(z/sqrt(r2)):(r[2]>0.0?PI/2.0:-PI/2.0);
    pos[1]=r2>1E-12?atan2(r[1],r[0]):0.0;
    pos[2]=sqrt(r2+z*z)-v;
}
/* euclid norm -----------------------------------------------------------------
* euclid norm of vector
* args   : double *a        I   vector a (n x 1)
*          int    n         I   size of vector a
* return : || a ||
*-----------------------------------------------------------------------------*/
double CNDGNSS::norm(const double *a, int n)
{
    return sqrt(dot(a,a,n));
}
/* geometric distance ----------------------------------------------------------
* compute geometric distance and receiver-to-satellite unit vector
* args   : double *rs       I   satellilte position (ecef at transmission) (m)
*          double *rr       I   receiver position (ecef at reception) (m)
*          double *e        O   line-of-sight vector (ecef)
* return : geometric distance (m) (0>:error/no satellite position)
* notes  : distance includes sagnac effect correction
*-----------------------------------------------------------------------------*/
double CNDGNSS::geodist(const double *rs, const double *rr, double *e)
{
    double r;
    int i;
    
    if (norm(rs,3)<RE_WGS84) return -1.0;
    for (i=0;i<3;i++) e[i]=rs[i]-rr[i];
    r=norm(e,3);
    for (i=0;i<3;i++) e[i]/=r;
    return r+OMGE*(rs[0]*rr[1]-rs[1]*rr[0])/CLIGHT;
}
////////////////////////////////////BLH2XYZ//////////////////////////////////////////
void  CNDGNSS::BLHTOXYZ (double B,double L,double H,double &x,double &y,double &z)//求空间直角坐标（将地面点的大地经纬度转换成空间直角坐标）;
{
	const  double  a_wgs84=6378137.000;
	const  double  b_wgs84=6356752.310;

	double a=a_wgs84;      // semi-major axis of reference ellipse [m]
	double b=b_wgs84;      // semi-minor axis of reference ellipse [m]
	double e2=0.00669437999014132;     // first eccentricity of reference ellipse []
	double N;      // prime vertical radius of curvature [m]
	double cosB,cosL,sinB,sinL;
	//double PI=3.141592653589793;
	//	BOOL result;

	cosB=cos(B);
	cosL=cos(L);
	sinB=sin(B);
	sinL=sin(L);
	N   = a / sqrt( 1.0 - e2*sinB*sinB );
	x=(N+H)*cosB*cosL;
	y=(N+H)*cosB*sinL;
	z=(N*(1.0-e2)+H)*sinB;


	return;
}
////////////////////////////////////XYZ2BLH//////////////////////////////////////////
void  CNDGNSS::XYZTOBLH (double x,double y,double z,double &B,double &L,double &H)//求大地经纬度（将地面点的坐标转换成大地经纬度）
{
	const  double  a_wgs84=6378137.000;
	const  double  b_wgs84=6356752.310;

	double a=a_wgs84;      // semi-major axis of reference ellipse [m]
	double b=b_wgs84;      // semi-minor axis of reference ellipse [m]
	double e2=0.00669437999014132;     // first eccentricity of reference ellipse []
	double N;      // prime vertical radius of curvature [m]
	double p;      // sqrt( x^2 + y^2 ) [m]
	double dtmp;   // temp
	double sinlat; // sin(lat)
	double lat;    // temp geodetic latitude  [rad]
	double lon;    // temp geodetic longitude [rad]
	double hgt;    // temp geodetic height    [m]
	//	BOOL result;

	// get necessary reference ellipse parameters
	//	result = GEODESY_GetReferenceEllipseParameters_A_B_E2( referenceEllipse, &a, &b, &e2 );

	if( x == 0.0 && y == 0.0 ) 
	{
		// at a pole    
		// most likely to happen while using a simulator
		// longitude is really unknown
		lon = 0.0; 		
		if( z < 0 )
		{
			hgt = -z - b;
			lat = -PI/2.0;
		}
		else
		{
			hgt = z - b;
			lat = PI/2.0;
		}
	}
	else
	{
		p = sqrt( x*x + y*y );

		// unique solution for longitude
		// best formula for any longitude and applies well near the poles
		// pp. 178 reference [2]
		lon = 2.0 * atan2( y , ( x + p ) );		
		// set approximate initial latitude assuming a height of 0.0
		lat = atan( z / (p * (1.0 - e2)) );
		hgt = 0.0;
		do
		{ 
			dtmp = hgt;
			sinlat = sin(lat);
			N   = a / sqrt( 1.0 - e2*sinlat*sinlat );
			hgt = p / cos(lat) - N;
			lat = atan( z / (p * ( 1.0 - e2*N/(N + hgt) )) );      

		} while( fabs( hgt - dtmp ) > 0.0001 );  // 0.1 mm convergence for height
	}


	B = lat;
	L = lon;  
	H = hgt;//这一块在考虑考虑看看怎么处理到底返回什么
	//Geod.x  = lat;//
	//Geod.y = lon;  
	//Geod.z = hgt;
	return;
}
////////////////////////////////////XYZ2NEU//////////////////////////////////////////
void CNDGNSS::XYZ2NEU(double XYZ0[], double XYZ1[], double NEU[])
	// to calculate NEU 
	// 2007 creaded by Huizhong Zhu.
	// YXZ: Cartesian coordinates (X, Y, Z).
	// NEU: Local coordinates (North, East, Up).
{
	int		i,j;
	double	XYZ[3],BLH[3];
	double	Unit[3][3];		// Unit vectors.

	XYZTOBLH(XYZ0[0],XYZ0[1],XYZ0[2],BLH[0],BLH[1],BLH[2]);
	// Define unit vectors.
	// North
	Unit[0][0]=-sin(BLH[0])*cos(BLH[1]);
	Unit[0][1]=-sin(BLH[0])*sin(BLH[1]);
	Unit[0][2]=cos(BLH[0]);
	// East
	Unit[1][0]=-sin(BLH[1]);
	Unit[1][1]=cos(BLH[1]);
	Unit[1][2]=0.0;
	// Up
	Unit[2][0]=cos(BLH[0])*cos(BLH[1]);
	Unit[2][1]=cos(BLH[0])*sin(BLH[1]);
	Unit[2][2]=sin(BLH[0]);
	// Define baseline vector.
	for(i=0;i<3;i++)
		XYZ[i]=XYZ1[i]-XYZ0[i];
	for(i=0;i<3;i++)
	{
		NEU[i]=0.0;
		for(j=0;j<3;j++)
			NEU[i]+=XYZ[j]*Unit[i][j];
	}
	return;
}

///////////////////////////////////////////////求逆矩阵;
void CNDGNSS::M_Inv(int n,double *a,double *c)      //矩阵求逆	 n为要求的矩阵的阶数   a(n×n)为要求逆的矩阵 c为a的逆矩阵;
{
	double at;
	double bt;
	double am;
	int i,j,k;
	int tt;
	int N=2*n;
	double *p=new double[n*N];	
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
			p[N*i+j]=a[n*i+j];
		}
		for(j=n;j<N;j++)
		{
			if(i==j-n)
				p[N*i+j]=1;
			else
				p[N*i+j]=0;
		}
	}

	for(k=0;k<n;k++)						//求解;
	{
		at=fabs(p[N*k+k]);
		tt=k;
		for(j=k+1;j<n;j++)
		{
			bt=fabs(p[N*j+k]);
			if(at<bt)
			{
				at=bt;
				tt=j;
			}
		}
		if(tt!=k)
			for(j=k;j<N;j++)
			{
				am=p[N*k+j];
				p[N*k+j]=p[N*tt+j];
				p[N*tt+j]=am;
			}
			/*if(at<0.0001)
			{
			return;
			}*/
			am=1/p[N*k+k];
			for(j=k;j<N;j++)
			{
				p[N*k+j]=p[N*k+j]*am;
			}

			for(i=0;i<n;i++)
			{
				if(k!=i)
				{
					am=p[N*i+k];
					for(j=0;j<N;j++)
					{
						p[N*i+j]=p[N*i+j]-p[N*k+j]*am;
					}
				}
			}
	}
	for(i=0;i<n;i++)
		for(j=0;j<n;j++)
			c[n*i+j]=p[N*i+(j+n)];
	delete []p;
}
//////////////////////////////////////////////////////////////矩阵转置;
void CNDGNSS::M_Tra(int m,int n,double *a,double *c)				//矩阵转置 a为要转置的矩阵，m为矩阵的行，n为矩阵的列；c为转置后的矩阵;
{                                                                                                                                             
	for(int i=0;i<m;i++)                                                                                                                  
	{                                                                                                                                     
		for(int j=0;j<n;j++)                                                                                                          
			c[j*m+i]=a[i*n+j];                                                                                                    
	}                                                                                                                                     
} 
//////////////////////////////////////////////////////////////矩阵乘法;
void CNDGNSS::M_Mul(int m,int s,int n,double *a,double *b,double *c)//矩阵乘法 a(m×s)，b(s×n)为要相乘的两矩阵，c为矩阵相乘结果;   
{                                                                                                                                      
	for(int i=0;i<m;i++)                                                                                                           
	{                                                                                                                              
		for(int j=0;j<n;j++)                                                                                                   
		{                                                                                                                      
			c[i*n+j]=0;                                                                                                    
			for(int k=0;k<s;k++)                                                                                           
			{                                                                                                              
				c[i*n+j]=c[i*n+j]+a[i*s+k]*b[k*n+j];                                                                   
			}                                                                                                              
		}                                                                                                                      
	}                                                                                                                              
}                                                                                                                                      

int CNDGNSS::UTC2GPST(o_tim  *o_tm,double *GPST_second)
{
	int dayofyear; //当前时间在今年是第几天
	int dofm;      //每个月的天数
	int m;
	//--------------------------------------当前时间所在的年-----------------------------	
	if(o_tm->month==1)
		dayofyear=o_tm->day-1;
	else
	{
		dayofyear=0;
		for(m=1;m<o_tm->month;m++)
		{
			switch (m)
			{
			case 1:dofm=31;break;
			case 2:dofm=28;break;
			case 3:dofm=31;break;
			case 4:dofm=30;break;
			case 5:dofm=31;break;
			case 6:dofm=30;break;
			case 7:dofm=31;break;
			case 8:dofm=31;break;
			case 9:dofm=30;break;
			case 10:dofm=31;break;
			case 11:dofm=30;break;
			}
			dayofyear+=dofm;
		}
		dayofyear+=o_tm->day-1;	//再加上当月的天数;
		if(m>=2)
		{
			if (o_tm->year % 4 == 0 && o_tm->year % 100 != 0 || o_tm->year % 400 == 0)//判断是否为闰年;
				dayofyear += 1;	//闰年2月加1天
		}
	}
	//--------------------------------------当前时间所在年的上一年至1980年-----------------------------			
	int dofy=361;					//从1980年开始，到当前年的前一年的总天数，令初值dofy=360为1980.1.6开始算的1980年的天数;
	int y;
	for(y=1981;y<o_tm->year;y++)
	{
		dofy+=365;
		if((y % 4 == 0 && y % 100 != 0 || y % 400 == 0))
			dofy+=1;
	}
	int dayofall;					//当前时间的总天数;
	dayofall=dofy+dayofyear;		//到此计算出了当前时间的总天数;
	int GPST_week;				//GPST中的整周数
	GPST_week=int(dayofall/7);
	int dayofweek;				//GPST中不满一周的天数;
	dayofweek=dayofall-GPST_week*7;
	*GPST_second=dayofweek*24*60*60+o_tm->hour*60*60+o_tm->minute*60+o_tm->second;//不满一周天数换成GPST(秒);

	return 0;
}
int CNDGNSS::choose_sat(double XK,double YK,double ZK,double *EL,double *B,double *L,double *H,double X,double Y,double Z)
{

	//double X,Y,Z;//代表基准站/流动站WGS84系下坐标;   	 	 	 	 	 	 
	//double B,L,H;										//接收机位置在大地坐标系下的初始坐标
	//double PI=3.14159265358979;
	double a=6378137.0000,b=6356752.414245;      
	double e=sqrt((a*a-b*b)/(a*a));
	double NN,B0,B1;
	B0=atan(Z/sqrt(X*X+Y*Y));		
	do
	{	
		B1=B0;
		NN=a/sqrt(1-e*e*sin(B1)*sin(B1));		
		B0=atan( (Z+NN*e*e*sin(B1))/sqrt(X*X+Y*Y) );
	}while(fabs(B1-B0)>0.00000000001);
	*B=B0;
	*L=atan(abs(Y/X));
	if(Y>0&&X<0)
		*L=PI-*L;
	*H=sqrt(X*X+Y*Y)/cos(*B)-a/sqrt(1-e*e*sin(*B)*sin(*B));

	//printf("%10.8f %10.8f %10.8f\n",B,L,H);
	//double glo_coor->X[*N],glo_coor->Y[*N],Zs=22230426.7160245700;//卫星在WGS84坐标系下的坐标
	double det_x,det_y,det_z;
	det_x=XK-X;
	det_y=YK-Y;
	det_z=ZK-Z;

	double Xp,Yp,Zp;//卫星在北东天站心坐标系下的坐标;
	Xp=-sin(*B)*cos(*L)*det_x-sin(*B)*sin(*L)*det_y+cos(*B)*det_z;
	Yp=-sin(*L)*det_x+cos(*L)*det_y;
	Zp=cos(*B)*cos(*L)*det_x+cos(*B)*sin(*L)*det_y+sin(*B)*det_z;
	//printf("%10.8f %10.8f %10.8f\n",Xp,Yp,Zp);
	//double EL;//卫星高度角（仰角）范围为（-90°~90°）
	if(Zp==0)
		*EL=0;
	else if(sqrt(Xp*Xp+Yp*Yp)==0)
		*EL=PI/2;
	*EL=atan(Zp/sqrt(Xp*Xp+Yp*Yp));//此处不用加绝对值了,因为sqrt(Xp*Xp+Yp*Yp)>0，Zp>0时（sin(EL)>0），EL介于(0~90°)第一象限；Zp<0时（sin(EL)<0，EL介于(-90°~0°)第四象限
	return 0;
}

//glonass卫星坐标
int CNDGNSS::calculate_glo_satellite_coor(GEPH geph[],int jj,DATG dg[],int sta_num,double rs[],double dts[])
{
	int glo_prn = dg[sta_num].prn[jj];
	int j;
	double var;
	double dt=0.0,pr=0.0;
	double rst[3],dtst[1],tt=1E-3;
	memset(dts,0x00,sizeof(dts));
	memset(&var,0x00,sizeof(var));
	gtime_t recv_time,recvt1;
	memset(&recv_time,0x00,sizeof(gtime_t));
	memset(&recvt1,0x00,sizeof(gtime_t));
	recv_time=gpst2time(dg[sta_num].tg.week, dg[sta_num].tg.second);

	/* transmission time by satellite clock */
	for (j=0,pr=0.0;j<NFREQ;j++) if ((pr=dg[sta_num].data[jj][j])>0.0) break;
	if (j>=NFREQ) {
		return 0;
	}
	recvt1=timeadd(recv_time,-pr/CLIGHT);
	/* satellite clock bias by broadcast ephemeris */
	dt=geph2clk(recvt1, geph, glo_prn);
	recvt1=timeadd(recvt1,-dt);
	/* satellite position and clock at transmission time */
	geph2pos(recvt1, geph, glo_prn,rs,dts,&var);
	recvt1=timeadd(recvt1,tt);
	geph2pos(recvt1,geph,glo_prn,rst,dtst,&var);
	/* satellite velocity and clock drift by differential approx */
    for (int i=0;i<3;i++) rs[i+3]=(rst[i]-rs[i])/tt;
    dts[1]=(dtst[0]-dts[0])/tt;
	return 1;
}

const double  GM=398600.44,a=6378.136,C20=-0.00108263,we=7.292115e-5;

double CNDGNSS::f_ax(double x,double y,double z,double u,double v,double w,double xls)
{

	double r=sqrt(x*x+y*y+z*z);
	return -MU_GLO*x/(r*r*r)+1.5*C20*MU_GLO*RE_GLO*RE_GLO*x*(1-5*z*z/(r*r))/(r*r*r*r*r)+we*we*x+2*we*v+xls;
}
double CNDGNSS::f_ay(double x,double y,double z,double u,double v,double w,double yls)
{

	double r=sqrt(x*x+y*y+z*z);
	return -MU_GLO*y/(r*r*r)+1.5*C20*MU_GLO*RE_GLO*RE_GLO*y*(1-5*z*z/(r*r))/(r*r*r*r*r)+we*we*y-2*we*u+yls;
}
double CNDGNSS::f_az(double x,double y,double z,double u,double v,double w,double zls)
{

	double r=sqrt(x*x+y*y+z*z);
	return -MU_GLO*z/(r*r*r)+1.5*C20*MU_GLO*RE_GLO*RE_GLO*z*(3-5*z*z/(r*r))/(r*r*r*r*r)+zls;
}

int CNDGNSS::calculate_glo_satellite_coor_lhf(GEPH geph[],int jj,DATG dg[],int sta_num,double delt,double *X,double *Y,double *Z,double *RECD)//计算卫星位置坐标;
{
	int glo_prn = dg[sta_num].prn[jj];
	double	K1,K2,K3,K4;
	double	L1,L2,L3,L4;
	double	M1,M2,M3,M4;
	double	N1,N2,N3,N4;
	double	P1,P2,P3,P4;
	double	Q1,Q2,Q3,Q4;
	double	h;			//步长30(s)
	if(delt<0)
		h=-30;
	else
		h=30;
	int	n=int(delt/h);		//满30秒的循环次数;

	double x[200],y[200],z[200];
	double u[200],v[200],w[200];

	x[0]=geph[glo_prn].a[5];//posx
	y[0]=geph[glo_prn].a[9];//posy
	z[0]=geph[glo_prn].a[13];//posz
    u[0]=geph[glo_prn].a[6];//velx
	v[0]=geph[glo_prn].a[10];//vely
	w[0]=geph[glo_prn].a[14];//velz

	double gloacc[3];
	memset(gloacc,0x00,sizeof(gloacc));
	gloacc[0]=geph[glo_prn].a[7];//accx
	gloacc[1]=geph[glo_prn].a[11];//accy
	gloacc[2]=geph[glo_prn].a[15];//accz

	int i;
	for(i=0;i<n+1;i++)
	{	

		double h1;//不满30的步长
		if(delt<0)
			h1=delt+i*30;
		else
			h1=delt-i*30;
		if(fabs(h1)<30)
			h=h1;	

		K1=h*f_ax(x[i],y[i],z[i],u[i],v[i],w[i],gloacc[0]);
		L1=h*f_ay(x[i],y[i],z[i],u[i],v[i],w[i],gloacc[1]);
		M1=h*f_az(x[i],y[i],z[i],u[i],v[i],w[i],gloacc[2]);
		N1=h*u[i];
		P1=h*v[i];
		Q1=h*w[i];

		K2=h*f_ax(x[i]+N1/2,y[i]+P1/2,z[i]+Q1/2,u[i]+K1/2,v[i]+L1/2,w[i]+M1/2,gloacc[0]);
		L2=h*f_ay(x[i]+N1/2,y[i]+P1/2,z[i]+Q1/2,u[i]+K1/2,v[i]+L1/2,w[i]+M1/2,gloacc[1]);
		M2=h*f_az(x[i]+N1/2,y[i]+P1/2,z[i]+Q1/2,u[i]+K1/2,v[i]+L1/2,w[i]+M1/2,gloacc[2]);
		N2=h*(u[i]+K1/2);
		P2=h*(v[i]+L1/2);
		Q2=h*(w[i]+M1/2);

		K3=h*f_ax(x[i]+N2/2,y[i]+P2/2,z[i]+Q2/2,u[i]+K2/2,v[i]+L2/2,w[i]+M2/2,gloacc[0]);
		L3=h*f_ay(x[i]+N2/2,y[i]+P2/2,z[i]+Q2/2,u[i]+K2/2,v[i]+L2/2,w[i]+M2/2,gloacc[1]);
		M3=h*f_az(x[i]+N2/2,y[i]+P2/2,z[i]+Q2/2,u[i]+K2/2,v[i]+L2/2,w[i]+M2/2,gloacc[2]);
		N3=h*(u[i]+K2/2);
		P3=h*(v[i]+L2/2);
		Q3=h*(w[i]+M2/2);

		K4=h*f_ax(x[i]+N3,y[i]+P3,z[i]+Q3,u[i]+K3,v[i]+L3,w[i]+M3,gloacc[0]);
		L4=h*f_ay(x[i]+N3,y[i]+P3,z[i]+Q3,u[i]+K3,v[i]+L3,w[i]+M3,gloacc[1]);
		M4=h*f_az(x[i]+N3,y[i]+P3,z[i]+Q3,u[i]+K3,v[i]+L3,w[i]+M3,gloacc[2]);
		N4=h*(u[i]+K3);
		P4=h*(v[i]+L3);
		Q4=h*(w[i]+M3);

		u[i+1]=u[i]+(K1+2*K2+2*K3+K4)/6;
		v[i+1]=v[i]+(L1+2*L2+2*L3+L4)/6;
		w[i+1]=w[i]+(M1+2*M2+2*M3+M4)/6;
		x[i+1]=x[i]+(N1+2*N2+2*N3+N4)/6;
		y[i+1]=y[i]+(P1+2*P2+2*P3+P4)/6;
		z[i+1]=z[i]+(Q1+2*Q2+2*Q3+Q4)/6;
	}
	double XX,YY,ZZ;
	XX= x[i]/**1000*/; 
	YY= y[i]/**1000*/;
	ZZ= z[i]/**1000*/;
	*X=-0.47+(XX-1.728e-6*YY-0.017e-6*ZZ)*(1+22e-9);		//组合定位PZ-90坐标要转化到统一的WGS-84坐标系下（BDS的CGCS2000和WGS-84坐标系基本一致，定位精度在2cm以下才需要转化）;
	*Y=-0.51+(1.728e-6*XX+YY+0.076e-6*ZZ)*(1+22e-9);
	*Z=-1.56+(0.017e-6*XX-0.076e-6*YY+ZZ)*(1+22e-9);
	*RECD=-2*(*X*u[i]+*Y*v[i]+*Z*w[i])/**1000*//299792458;		//相对论效应影响   XX、YY、ZZ已经化为m，u、v、w还是km/s, 所以要乘以1000;
	return 0;
}

int CNDGNSS::calculate_gnss_satellite_coor(GEPH m_GEPHTemp[],int jj,DATG dg[],int sta_num,double current_time,double transmit_t,double *Xk,double *Yk,double *Zk,double *RECD,int GNSS_type)
	//current_time为接收机当前时间，通过指针从观测文件中传过来，已经改正到GPST下的秒，来计算的就是此刻的卫星位置
{

	double GM=3.9860047e14;
	double A=m_GEPHTemp[dg[sta_num].prn[jj]].a[10]*m_GEPHTemp[dg[sta_num].prn[jj]].a[10]; //长半轴;
	double n0=sqrt(GM/(A*A*A));							//平均角速度;

	double C=299792458.0;
	double tk=current_time-transmit_t-m_GEPHTemp[dg[sta_num].prn[jj]].a[11];   //归化时间//current_time为接收机当前时间，已经改正到GPST下的秒
	if (tk>302400)
		tk=tk-604800;
	if (tk<-302400)
		tk=tk+604800;
	double n=n0+m_GEPHTemp[dg[sta_num].prn[jj]].a[5];	//改正的平均角速度;
	double mk=m_GEPHTemp[dg[sta_num].prn[jj]].a[6]+n*tk;//平近点角;

	double ek1,ek2,ek;									//迭代计算偏近点角ek;
	ek1=mk;					
	do
	{
		ek2=ek1;
		ek1=mk+m_GEPHTemp[dg[sta_num].prn[jj]].a[8]*sin(ek2);
	}while(fabs(ek1-ek2)>1.0e-12);
	ek=ek1;

	double a,b,fk;										//计算真近点角 fk;
	//double PI=3.141592653589793;
	a=(cos(ek)-m_GEPHTemp[dg[sta_num].prn[jj]].a[8])/(1-m_GEPHTemp[dg[sta_num].prn[jj]].a[8]*cos(ek));             //a=cos(fk)
	b=sin(ek)*sqrt(1-m_GEPHTemp[dg[sta_num].prn[jj]].a[8]*m_GEPHTemp[dg[sta_num].prn[jj]].a[8])/(1-m_GEPHTemp[dg[sta_num].prn[jj]].a[8]*cos(ek));//b=sin(fk)
	if(a==0)
		fk=PI/2;
	else if(b==0)
		fk=PI;
	else 
	{
		fk=atan(fabs(b/a));								//第1象限     tan(fk)=b/a=sin(fk)/cos(fk)  
		if(a>0&&b<0)									//第4象限
			fk=2*PI-fk;
		else if(a<0&&b<0)								//第3象限
			fk=PI+fk;
		else if(a<0&&b>0)								//第2象限
			fk=PI-fk;
	}

	double fai_k=fk+m_GEPHTemp[dg[sta_num].prn[jj]].a[17];					//维度参数;
	double det_uk,det_rk,det_ik;						//周期改正项;
	det_uk=m_GEPHTemp[dg[sta_num].prn[jj]].a[9]*sin(2*fai_k)+m_GEPHTemp[dg[sta_num].prn[jj]].a[7]*cos(2*fai_k);
	det_rk=m_GEPHTemp[dg[sta_num].prn[jj]].a[4]*sin(2*fai_k)+m_GEPHTemp[dg[sta_num].prn[jj]].a[16]*cos(2*fai_k);
	det_ik=m_GEPHTemp[dg[sta_num].prn[jj]].a[14]*sin(2*fai_k)+m_GEPHTemp[dg[sta_num].prn[jj]].a[12]*cos(2*fai_k);

	double uk=fai_k+det_uk;								//改正后的维度参数;
	double rk=A*(1-m_GEPHTemp[dg[sta_num].prn[jj]].a[8]*cos(ek))+det_rk;	//改正后的向径;
	double ik=m_GEPHTemp[dg[sta_num].prn[jj]].a[15]+det_ik+m_GEPHTemp[dg[sta_num].prn[jj]].a[19]*tk;//改正后的倾角;

	double xk,yk,zk;									//卫星在轨道平面中坐标;
	xk=rk*cos(uk);
	yk=rk*sin(uk);
	zk=0;
	double we=7.2921151467e-5;
	if (GNSS_type==1)//GPS系统
	{
		double Lk=m_GEPHTemp[dg[sta_num].prn[jj]].a[13]+(m_GEPHTemp[dg[sta_num].prn[jj]].a[18]-we)*tk-we*m_GEPHTemp[dg[sta_num].prn[jj]].a[11];//观测瞬间升交点的经度值;

		//卫星在地固坐标系中坐标,通过指针传出去;
		*Xk=cos(Lk)*xk-sin(Lk)*cos(ik)*yk+sin(Lk)*sin(ik)*zk;
		*Yk=sin(Lk)*xk+cos(Lk)*cos(ik)*yk-cos(Lk)*sin(ik)*zk;
		*Zk=     0*xk       +sin(ik)*yk       +cos(ik)*zk;
	}
	else if (GNSS_type==2)//BDS系统
	{
		double Lk;
		if (dg[sta_num].prn[jj]==161||dg[sta_num].prn[jj]==162||dg[sta_num].prn[jj]==163||dg[sta_num].prn[jj]==164||dg[sta_num].prn[jj]==165)	//GEO卫星位置计算20150805;
		{
			double Xkk,Ykk,Zkk;
			Lk=m_GEPHTemp[dg[sta_num].prn[jj]].a[13]+m_GEPHTemp[dg[sta_num].prn[jj]].a[18]*tk-we*m_GEPHTemp[dg[sta_num].prn[jj]].a[11];			//观测瞬间升交点的经度值;
			Xkk=cos(Lk)*xk-sin(Lk)*cos(ik)*yk+sin(Lk)*sin(ik)*zk;
			Ykk=sin(Lk)*xk+cos(Lk)*cos(ik)*yk-cos(Lk)*sin(ik)*zk;
			Zkk=0*xk+sin(ik)*yk+cos(ik)*zk;

			double n=-PI/36;	//n=-5°
			double alp=we*tk; 
			*Xk= Xkk*cos(alp)+Ykk*sin(alp)*cos(n)+Zkk*sin(alp)*sin(n);
			*Yk=-Xkk*sin(alp)+Ykk*cos(alp)*cos(n)+Zkk*cos(alp)*sin(n);
			*Zk=-sin(n)*Ykk+Zkk*cos(n);
		}
		else
		{
			Lk=m_GEPHTemp[dg[sta_num].prn[jj]].a[13]+(m_GEPHTemp[dg[sta_num].prn[jj]].a[18]-we)*tk-we*m_GEPHTemp[dg[sta_num].prn[jj]].a[11];	//观测瞬间升交点的经度值;						
			*Xk=cos(Lk)*xk-sin(Lk)*cos(ik)*yk+sin(Lk)*sin(ik)*zk;	//卫星在地固坐标系中坐标;		
			*Yk=sin(Lk)*xk+cos(Lk)*cos(ik)*yk-cos(Lk)*sin(ik)*zk;
			*Zk=0*xk+sin(ik)*yk+cos(ik)*zk;
		}
	}


	double e_sinek ;												//RECD relativistic_effect_correction_distence相对论影响距离
	e_sinek=m_GEPHTemp[dg[sta_num].prn[jj]].a[9]*sin(ek);
	*RECD=-2*m_GEPHTemp[dg[sta_num].prn[jj]].a[11]*sqrt(GM)*e_sinek/299792458;

	return 0;
}

void CNDGNSS::GLONASS_POS_MODULE(GEPH geph[],DATG dg[],int sta_num,double &X0,double &Y0,double &Z0,double *swj,double *RR,double rs[],int gnss_num)

{
	
	double dts[2]={0.0};
	double GPST_second;
	GPST_second=dg[sta_num].tg.second;

	double X=0,Y=0,Z=0;

	double R=0;								//卫地距离;
	double C=299792458.0;

	int prn_satellite = dg[sta_num].prn[gnss_num];
	if (geph[prn_satellite].a[8] == 1)//卫星不健康
		return;
	if (geph[prn_satellite].a[5] == 0.0||geph[prn_satellite].a[9] == 0.0||geph[prn_satellite].a[13] == 0.0)
		return;

	calculate_glo_satellite_coor(geph,gnss_num,dg,sta_num,rs,dts);

	double rr[3]={0},r2suv[3]={0},pos[3]={0},azel[2]={0};
	double EL = 0;

	rr[0]=X0;
	rr[1]=Y0;
	rr[2]=Z0;
	*RR = sqrt(pow(rs[0] - X0, 2) + pow(rs[1] - Y0, 2) + pow(rs[2] - Z0, 2));	//卫地距;

	geodist(rs,rr,r2suv);
	ecef2pos(rr,pos);
	EL=satazel(pos,r2suv,azel);

	if (fabs(EL*R2D) >= 10 && dg[sta_num].data[gnss_num][0]>0 && dg[sta_num].data[gnss_num][2]>0 && fabs(dg[sta_num].data[gnss_num][0]-dg[sta_num].data[gnss_num][2])<20)						//设高度角为10度((PI/18=0.17453292519943))，小于10的卫星舍去  15度 PI/12=0.2617993877991
	{
		//trop_mod(&dtrop,pos[2],EL);				//对流层模型改正（SAAS改进模型，内置了映射函数）
		
		*swj = dg[sta_num].data[gnss_num][0] /*+ RECD */+ (dts[0]+dts[1])*C ;
	}
	else									//高度角为10度((PI/18=0.17453292519943))，小于10的卫星舍去  15度 PI/12=0.2617993877991
	{
		*RR = 0;
		*swj = 0;
		rs[0] = 0;
		rs[1] = 0;
		rs[2] = 0;
	}

}
void CNDGNSS::GLO_POS_MODULE(GEPH m_GEPHTemp[],DATG dg[],int sta_num,double &X0,double &Y0,double &Z0,double *swj,double *RR,double *XK,double *YK,double *ZK,int gnss_num)//GNSS_type：1代表GPS，2代表BDS
{
	GPST glo_gpst;
	int week;
	memset(&glo_gpst,0x00,sizeof(glo_gpst));
	double GPST_second;
	GPST_second=dg[sta_num].tg.second;

	//double ep[6]={0.0};
	//gtime_t O_time=gpst2time(dg[sta_num].tg.week,dg[sta_num].tg.second);
	//time2epoch(O_time,ep);
	int prn_satellite = dg[sta_num].prn[gnss_num];

	if (m_GEPHTemp[prn_satellite].a[8] == 1)//卫星不健康
		return;
	if (m_GEPHTemp[prn_satellite].a[5] == 0.0||m_GEPHTemp[prn_satellite].a[9] == 0.0||m_GEPHTemp[prn_satellite].a[13] == 0.0)
		return;

	gtime_t glo_t;//glonass电文GPST/* epoch of epherides (gpst) */
	glo_t.time=m_GEPHTemp[prn_satellite].a[0];
	glo_t.sec =m_GEPHTemp[prn_satellite].a[1];
	glo_gpst.second=time2gpst(glo_t, &week);
	glo_gpst.week=week;

	double deltt = fabs(glo_gpst.second - GPST_second); 

	if(deltt>1350)//还要保证最短的的时间不能大15min+7.5min;
	{
		return;
	}

	double X=0,Y=0,Z=0;
	double transmit_t;
	double RECD;
	double T_receive=GPST_second;
	double transmit_t0=0.07;		//令信号传输时间为0.07s
	double R=0;					//卫地距离;
	double C=299792458.0;
	double delt;
	do 
	{	
		transmit_t=transmit_t0;
		double Setout_t=T_receive-transmit_t;
		delt=Setout_t-glo_gpst.second-15;	//信号发射时刻相对于星历参考时刻;
		calculate_glo_satellite_coor_lhf(m_GEPHTemp,gnss_num,dg,sta_num,delt,&X,&Y,&Z,&RECD);	//计算卫星位置坐标;
		R=sqrt(pow(X-X0,2)+pow(Y-Y0,2)+pow(Z-Z0,2));									//pow(底数，幂)，如3的平方pow(3，2);
		transmit_t0=R/C;
	} while (fabs(transmit_t-transmit_t0)>10e-12);
	double we=7.292115e-5;
	double det_alph=we*transmit_t0;	//transmit_t0信号传播时间

	*XK= X + Y * sin(det_alph);	//考虑地球自传改正后卫星在地固坐标系中坐标;
	*YK=-X * sin(det_alph) + Y;	//传出计算的卫星坐标;
	*ZK= Z;
	*RR=sqrt(pow(*XK-X0,2)+pow(*YK-Y0,2)+pow(*ZK-Z0,2));	
	//double swj;
	//ion(&swj,&o_bs,i,"R");			//伪距电离层改正;
	double EL=0,B=0,L=0,H=0;
	double dtrop;
	//choose_sat(*R_XK,*R_YK,*R_ZK,&EL,&B,&L,&H);	//筛除卫星高度角小于规定值的卫星（比如小于10°）
	double rs[3]={0.0},rr[3]={0.0},r2suv[3]={0},pos[3]={0},azel[2]={0};
	rs[0]=*XK;
	rs[1]=*YK;
	rs[2]=*ZK;
	rr[0]=X0;
	rr[1]=Y0;
	rr[2]=Z0;

	geodist(rs,rr,r2suv);
	ecef2pos(rr,pos);
	EL=satazel(pos,r2suv,azel);

	if(fabs(EL*R2D)>=15)			//设高度角为15度((PI/18=0.17453292519943))，小于10的卫星舍去  15度 PI/12=0.2617993877991
	{
		//trop_mod(&dtrop,H,EL);					//对流层模型改正（SAAS改进模型，内置了映射函数）
		double t_toe=delt-transmit_t0;			//非常注意啊：这点我之前一直弄错啦;直到20130309才发现
		double Ts=m_GEPHTemp[prn_satellite].a[2]-m_GEPHTemp[prn_satellite].a[3]*t_toe;//GLONASS卫星钟差
		double Ts_swj=Ts*C;		//卫星钟差改正伪距;
		//*r_swj=swj+Ts_swj-dtrop+RECD;	//电离层，对流层，卫星钟差，相对论效应改正后的伪距;
		*swj = dg[sta_num].data[gnss_num][0] + RECD + Ts_swj ;
	}
	else							//高度角为10度((PI/18=0.17453292519943))，小于10的卫星舍去  15度 PI/12=0.2617993877991
	{
		*RR = 0;
		*swj = 0;
		*XK = 0;
		*YK = 0;
		*ZK = 0;
	}
}

void CNDGNSS::GNSS_POS_MODULE(GEPH m_GEPHTemp[],DATG dg[],int sta_num,double &X0,double &Y0,double &Z0,double *swj,double *RR,double *XK,double *YK,double *ZK,int gnss_num,int GNSS_type)//GNSS_type：1代表GPS，2代表BDS

{
	double GPST_second;
	GPST_second=dg[sta_num].tg.second;
	if(GNSS_type==2)						//2代表BDS系统
		GPST_second-=14;
	double X=0,Y=0,Z=0;
	double transmit_t;

	double transmit_t0=0.07;				//令信号传输时间为0.07s
	double R=0;								//卫地距离;
	double C=299792458.0;
	double RECD;							//relativistic_effect_correction_distence相对论影响距离


	int prn_satellite = dg[sta_num].prn[gnss_num];
	if (m_GEPHTemp[prn_satellite].a[24] == 1)//卫星不健康
		return;

	double deltt = fabs(m_GEPHTemp[prn_satellite].a[11] - GPST_second); 

	//TRACE("prn=%c:%d deltt=%f\n", dg[sta_num].kind[gnss_num], prn_satellite, deltt);
	//	fprintf_s(m_fpche, "prn=%c:%d deltt=%f\n", dg[sta_num].kind[gnss_num], prn_satellite, deltt);


	if (GNSS_type == 1)//GPS
	{			
		if (deltt>7260)//toe时间过长，大于2h 有可能整点星历更新不及时
			return;
	}
	if (GNSS_type == 2)//BDS
	{						
		if(deltt>3660)//toe时间过长，大于1h，有可能整点星历更新不及时
			return;
	}
	do
	{
		transmit_t = transmit_t0;
		calculate_gnss_satellite_coor(m_GEPHTemp, gnss_num, dg, sta_num, GPST_second, transmit_t, &X, &Y, &Z, &RECD, GNSS_type);//计算卫星位置坐标;
		R = sqrt(pow(X - X0, 2) + pow(Y - Y0, 2) + pow(Z - Z0, 2));		//pow(底数，幂)，如3的平方pow(3，2);
		transmit_t0 = R / C;
	} while (fabs(transmit_t - transmit_t0)>10e-15);
	double we = 7.2921151467e-5;
	double det_alph = we*transmit_t0;			//transmit_t0信号传播时间

	double rs[3]={0},rr[3]={0},r2suv[3]={0},pos[3]={0},azel[2]={0};
	double EL = 0;
	rs[0]=*XK = X + Y * sin(det_alph);				//考虑地球自传改正后卫星在地固坐标系中坐标;
	rs[1]=*YK = -X * sin(det_alph) + Y;				//传出计算的卫星坐标;
	rs[2]=*ZK = Z;
	rr[0]=X0;
	rr[1]=Y0;
	rr[2]=Z0;
	*RR = sqrt(pow(*XK - X0, 2) + pow(*YK - Y0, 2) + pow(*ZK - Z0, 2));	//卫地距;

	geodist(rs,rr,r2suv);
	ecef2pos(rr,pos);
	EL=satazel(pos,r2suv,azel);

	//ion(swj, dg, sta_num, gnss_num, GNSS_type);	//伪距电离层改正;

	//double EL = 0, B = 0, L = 0, H = 0;
	//double dtrop;
	//choose_sat(*XK, *YK, *ZK, &EL, &B, &L, &H, X0, Y0, Z0);			//筛除卫星高度角小于规定值的卫星（比如小于10°）
	if (fabs(EL*R2D) >= 10 && dg[sta_num].data[gnss_num][0]>0 && dg[sta_num].data[gnss_num][2]>0 && fabs(dg[sta_num].data[gnss_num][0]-dg[sta_num].data[gnss_num][2])<20)						//设高度角为10度((PI/18=0.17453292519943))，小于10的卫星舍去  15度 PI/12=0.2617993877991
	{
		//trop_mod(&dtrop,pos[2],EL);				//对流层模型改正（SAAS改进模型，内置了映射函数）
		double t_toe = GPST_second - transmit_t0 - m_GEPHTemp[dg[sta_num].prn[gnss_num]].a[11];//非常注意啊：这点我之前一直弄错啦;直到20130309才发现
		double Ts = m_GEPHTemp[dg[sta_num].prn[gnss_num]].a[0] + m_GEPHTemp[dg[sta_num].prn[gnss_num]].a[1] * t_toe + m_GEPHTemp[dg[sta_num].prn[gnss_num]].a[2] * t_toe*t_toe;//GPS卫星钟差
		//double Ts_swj = Ts*C;
		//					*g_swj+=+Ts*C;
		//*swj=*swj+Ts_swj-dtrop+RECD;		//电离层，对流层，卫星钟差，相对论效应改正后的伪距;
		//					*g_swj=*g_swj+Ts*C-dtrop;
		//*swj = dg[sta_num].data[gnss_num][0] + RECD;
		*swj = dg[sta_num].data[gnss_num][0] + RECD + Ts*C ;
		//*swj = *swj + RECD + Ts*C;
	}
	else									//高度角为10度((PI/18=0.17453292519943))，小于10的卫星舍去  15度 PI/12=0.2617993877991
	{
		*RR = 0;
		*swj = 0;
		*XK = 0;
		*YK = 0;
		*ZK = 0;
	}

}
void CNDGNSS::trop_mod(double *dtrop,double H,double EL)		//对流层模型改正（SAAS改进模型，内置了映射函数）
{
	//double PI=3.141592653589793;
	double T=273+18-0.0065*H;
	double ew=0.5*pow(2.71828182845905,0.0006396*H)*pow(2.71828182845905,-37.2465+0.213166*T-0.000256908*T*T);
	double z=PI/2-EL;
	double P=1013.25*pow(1-0.000226*H,5.225);
	double HH=H/1000;
	double Bh=1.156*(HH-0.5)*(HH-1.0)*(HH-1.5)*(HH-2.0)*(HH-2.5)*(HH-3.0)*(HH-4)*(HH-5)/((0.0-0.5)*(0.0-1.0)*(0.0-1.5)*(0.0-2.0)*(0.0-2.5)*(0.0-3.0)*(0.0-4.0)*(0.0-5.0))
		+1.079*(HH-0.0)*(HH-1.0)*(HH-1.5)*(HH-2.0)*(HH-2.5)*(HH-3.0)*(HH-4)*(HH-5)/((0.5-0.0)*(0.5-1.0)*(0.5-1.5)*(0.5-2.0)*(0.5-2.5)*(0.5-3.0)*(0.5-4.0)*(0.5-5.0))
		+1.006*(HH-0.0)*(HH-0.5)*(HH-1.5)*(HH-2.0)*(HH-2.5)*(HH-3.0)*(HH-4)*(HH-5)/((1.0-0.0)*(1.0-0.5)*(1.0-1.5)*(1.0-2.0)*(1.0-2.5)*(1.0-3.0)*(1.0-4.0)*(1.0-5.0))
		+0.938*(HH-0.0)*(HH-0.5)*(HH-1.0)*(HH-2.0)*(HH-2.5)*(HH-3.0)*(HH-4)*(HH-5)/((1.5-0.0)*(1.5-0.5)*(1.5-1.0)*(1.5-2.0)*(1.5-2.5)*(1.5-3.0)*(1.5-4.0)*(1.5-5.0))
		+0.874*(HH-0.0)*(HH-0.5)*(HH-1.0)*(HH-1.5)*(HH-2.5)*(HH-3.0)*(HH-4)*(HH-5)/((2.0-0.0)*(2.0-0.5)*(2.0-1.0)*(2.0-1.5)*(2.0-2.5)*(2.0-3.0)*(2.0-4.0)*(2.0-5.0))
		+0.813*(HH-0.0)*(HH-0.5)*(HH-1.0)*(HH-1.5)*(HH-2.0)*(HH-3.0)*(HH-4)*(HH-5)/((2.5-0.0)*(2.5-0.5)*(2.5-1.0)*(2.5-1.5)*(2.5-2.0)*(2.5-3.0)*(2.5-4.0)*(2.5-5.0))
		+0.757*(HH-0.0)*(HH-0.5)*(HH-1.0)*(HH-1.5)*(HH-2.0)*(HH-2.5)*(HH-4)*(HH-5)/((3.0-0.0)*(3.0-0.5)*(3.0-1.0)*(3.0-1.5)*(3.0-2.0)*(3.0-2.5)*(2.0-4.0)*(2.0-5.0))
		+0.654*(HH-0.0)*(HH-0.5)*(HH-1.0)*(HH-1.5)*(HH-2.0)*(HH-2.5)*(HH-3)*(HH-5)/((4.0-0.0)*(4.0-0.5)*(4.0-1.0)*(4.0-1.5)*(4.0-2.0)*(4.0-2.5)*(4.0-3.0)*(4.0-5.0))
		+0.563*(HH-0.0)*(HH-0.5)*(HH-1.0)*(HH-1.5)*(HH-2.0)*(HH-2.5)*(HH-3)*(HH-4)/((5.0-0.0)*(5.0-0.5)*(5.0-1.0)*(5.0-1.5)*(5.0-2.0)*(5.0-2.5)*(5.0-3.0)*(5.0-4.0));
	*dtrop=(0.002277*(P+(1255/T+0.05)*ew-Bh*tan(z)*tan(z)))/cos(z);	
}
//单系统;
void CNDGNSS::recei_coor_single(rp *rcoor,sp scoor,double wj[],int *n,double SR[],double *GDOP,double *PDOP)
{	
	double RMS=0.0;
	int jinxingcuchatichu=0;
	int NN=*n;							//传过来的gps/bds卫星个数;
	int T=NN;
	int i;									//为了进行循环;

	double X0,Y0,Z0;
	X0=rcoor->X;
	Y0=rcoor->Y;
	Z0=rcoor->Z;

	int index;								//是否循环计算的标志,也即是是否有粗差的标志;
	//do
	//{
		*GDOP=0;
		*PDOP=0;
		index=0;
		double	*ll=			new	double[T]();		//课本P57参数  等加以double	(*ll)[1]=	 new	double[T][1];
		double	*mm=			new	double[T]();
		double	*nn=			new	double[T]();
		double	*L=			new	double[T]();	
		double	*A=			new	double[T*4]();	//状态矩阵A;
		double	*AT=			new	double[4*T]();	//状态矩阵A的转置;
		double	*P=			new	double[T*T]();	//权矩阵P;              ()是对动态内存进行初始化
		double	*ATP=		new	double[4*T]();	//A的转置乘以P;
		double	*ATPA=		new	double[4*4]();	//A的转置乘以P乘以A;
		double	*inv_ATPA=	new	double[4*4]();	//(A的转置乘以P乘以A)的逆;
		double	*ATPL=		new	double[4]();		//A的转置乘以P乘以L;
		double	*result=		new	double[4]();		//(A的转置乘以P乘以A)乘以(A的转置乘以P乘以L)，(inv_ATPA)(ATPL);


		//double	*AX=	new	double[T]();	//A乘以X;
		//double  *V=		new	double[T]();	//V=AX-L
		//double *VT=		new	double[1*T]();
		//double *VTP=	new	double[1*T]();
		//double *VTPV=	new	double[T*1]();
		///////////////////////////////////////////列法方程;


		if(NN>4)//rms有值;
		{
			//cout<<"系数矩阵B和L"<<endl;																	//☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀
			for(i=0;i<NN;i++)							
			{
				ll[i]=(scoor.X[i]-rcoor->X)/SR[i];
				mm[i]=(scoor.Y[i]-rcoor->Y)/SR[i];
				nn[i]=(scoor.Z[i]-rcoor->Z)/SR[i];
				A[i*4+0]=ll[i];
				A[i*4+1]=mm[i];
				A[i*4+2]=nn[i];
				A[i*4+3]=-1;
				//A[i*5+4]=0;								//初始化了就不需要了
				L[i]=SR[i]-wj[i];

				P[i*T+i]=1.0;	
				//printf("%8.3f%8.3f%8.3f%8.3f%8.3f%16.3f\n",A[i*5+0],A[i*5+1],A[i*5+2],A[i*5+3],A[i*5+4],L[i]);	//☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀


			}


			///////////////////////////////////////////通过函数的指针进行矩阵的运算，传出需要的矩阵;
			M_Tra(T,4,A,AT);							//矩阵转置	A的转置		传出AT;
			M_Mul(4,T,T,AT,P,ATP);						//矩阵相乘	AT乘P		传出ATP;
			M_Mul(4,T,4,ATP,A,ATPA);					//			ATP乘A		传出ATPA;
			M_Inv(4,ATPA,inv_ATPA);					//矩阵求逆	ATPA的逆		传出inv_ATPA;
			M_Mul(4,T,1,ATP,L,ATPL);					//			ATP乘L		传出ATPL;
			M_Mul(4,4,1,inv_ATPA,ATPL,result);			//			inv_ATPA乘ATPL传出result;

			//cout<<inv_ATPA[1]<<inv_ATPA[2]<<inv_ATPA[3]<<inv_ATPA[4]<<inv_ATPA[5]<<endl;
			//cout<<ATPL[1]<<ATPL[2]<<ATPL[3]<<ATPL[4]<<ATPL[5]<<endl;
			if(inv_ATPA!=NULL)
			{
				rcoor->X =result[0];
				rcoor->Y =result[1];
				rcoor->Z =result[2];
				rcoor->P1=result[3];


				for(i=0;i<4;i++)
					*GDOP+=inv_ATPA[i*4+i];
				*GDOP=sqrt(*GDOP);
				for(i=0;i<3;i++)
					*PDOP+=inv_ATPA[i*4+i];
				*PDOP=sqrt(*PDOP);                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
			}
			else
			{
				rcoor->X=0;
				rcoor->Y=0;
				rcoor->Z=0;
				rcoor->P1=0;

				printf("这个历元数据无法求解!\n");
				//system("pause");
			}

#if 0
			/*****************************************************************伪距测量中误差RMS**********************************************************************/	
			double X[4][1];
			X[0][0]=rcoor->X;
			X[0][1]=rcoor->Y;
			X[0][2]=rcoor->Z;
			X[0][3]=rcoor->P1;
			//double	*AX=	new	double[T]();			//A乘以X;
			M_Mul(T,4,1,A,X[0],AX);				//矩阵相乘;
			//double  *V=		new	double[T]();		//V=AX-L

			//cout<<"残差V矩阵"<<endl;				//☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀
			for(int p=0;p<T;p++)
			{
				V[p]=AX[p]-L[p];
				//printf("%16.8f\n",V[p]);			//☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀
			}
			//double *VT=		new	double[1*T]();
			//double *VTP=	new	double[1*T]();
			//double *VTPV=	new	double[T*1]();

			M_Tra(T,1,V,VT);						//矩阵转置	A的转置		传出AT;
			M_Mul(1,T,T,VT,P,VTP);					//矩阵相乘	AT乘P		传出ATP;
			M_Mul(1,T,1,VTP,V,VTPV);
			RMS=sqrt(*VTPV/(T-4));	
			//printf("\n\nRMS=%10.8f\n\n\n",*RMS);	//☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀
			double w[32];
			//cout<<"标准化残差w："<<endl;			//☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀
			for (i=0;i<T;i++)
			{
				w[i]=fabs(V[i])/(RMS*sqrt((T-1.0)/T));
				//printf("%16.8f\n",w[i]);			//☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀

			}

			//精度评定部分//
			double    XX=X0,YY=Y0,ZZ=Z0;                 //?????????????XX=-2777862.657,YY=4752777.981,ZZ=3210349.134;   真值动态时赋单点定位的值

			double delX=rcoor->X+X0-XX; 	 	 
			double delY=rcoor->Y+Y0-YY;
			double delZ=rcoor->Z+Z0-ZZ;

			double a=6378137.0000,b=6356752.414245;
			double e=sqrt((a*a-b*b)/(a*a));
			double N,B0,B1;
			double B,L1,H;
			double QQQ=sqrt(XX*XX+YY*YY);
			B0=atan(ZZ/QQQ);
			do
			{	
				B1=B0;
				N=a/sqrt(1-e*e*sin(B1)*sin(B1));
				B0=atan( (ZZ+N*e*e*sin(B1))/sqrt(XX*XX+YY*YY));
			}while(fabs(B1-B0)>0.00000000001);
			B=B0;
			L1=atan(abs(YY/XX));
			//double PI=3.141592653589793;
			if(YY>0&&XX<0)
				L1=PI-L1;
			H=sqrt(XX*XX+YY*YY)/cos(B)-a/sqrt(1-e*e*sin(B)*sin(B));

			double deltN,deltE,deltU;									//接收机在北东天(NEU)坐标系下的坐标;
			deltN=-sin(B)*cos(L1)*delX-sin(B)*sin(L1)*delY+cos(B)*delZ;		//北;N/B
			deltE=-sin(L1)*delX+cos(L1)*delY;								//东;E/L
			deltU=cos(B)*cos(L1)*delX+cos(B)*sin(L1)*delY+sin(B)*delZ;		//天;U/H
			double DNEU=deltN*deltN+deltE*deltE+deltU*deltU;
			if (fabs(deltN)<10&&fabs(deltE)<10)			
				//就是如果平面方向NE都小于1m就不进行出错剔除;改过，原来是5和4，动态没有已知坐标，用单点定位结果作为真值进行比较，肯定会差很大
			{
				delete	[]AX;
				delete	[]V;
				delete	[]VT;
				delete	[]VTP;
				delete	[]VTPV;

				delete	[]ll;
				delete	[]mm;
				delete	[]nn;
				delete	[]L;
				delete	[]A;
				delete	[]AT;
				delete	[]P;
				delete	[]ATP;
				delete	[]ATPA;
				delete	[]inv_ATPA;
				delete	[]ATPL;
				delete	[]result;
				break;
			}

			else
			{
				int NNN=0,PPP=0,TT=0;					//剔除后的GPS、BDS卫星数
				int B_bad_num=0,G_bad_num=0;			//BDS、GPS残差超限的个数;
				int pp=50;//这里是随便定义的一个初值，因为如果有超限的话pp的范围应该在“0——当前历元全部卫星个数”之间，肯定不超过50
				double W=0;
				for(int p=0;p<T;p++)
				{
					if(W<w[p])
					{
						W=w[p];
						pp=p;
					}

				}

				NNN=NN;
				//PPP=PP;
				index=1;				//说明有问题，要回代;
				rcoor->X=X0;			//既然有问题，那么rcoor的值要回归原始的已知值;
				rcoor->Y=Y0;
				rcoor->Z=Z0;

				//if(pp>NNN-1)			//说明是BDS卫星的
				//{
				//	for(int s=pp;s<T;s++)
				//	{
				//		bds_coor->X[s-NNN-B_bad_num]=bds_coor->X[s-NNN+1-B_bad_num];
				//		bds_coor->Y[s-NNN-B_bad_num]=bds_coor->Y[s-NNN+1-B_bad_num];
				//		bds_coor->Z[s-NNN-B_bad_num]=bds_coor->Z[s-NNN+1-B_bad_num];
				//		BDS_SR[s-NNN-B_bad_num]=BDS_SR[s-NNN+1-B_bad_num];
				//		bds_wj[s-NNN-B_bad_num]=bds_wj[s-NNN+1-B_bad_num];
				//	}
				//	B_bad_num++;
				//	PP=PPP-1;//新的BDS卫星个数
				//}
				//else	//说明是GPS卫星的
				//{
				for(int s=pp;s<NNN;s++)
				{
					scoor.X[s-G_bad_num]=scoor.X[s+1-G_bad_num];
					scoor.Y[s-G_bad_num]=scoor.Y[s+1-G_bad_num];
					scoor.Z[s-G_bad_num]=scoor.Z[s+1-G_bad_num];
					SR[s-G_bad_num]=SR[s+1-G_bad_num];
					wj[s-G_bad_num]=wj[s+1-G_bad_num];
				}
				G_bad_num++;
				NN=NNN-1;//新的GPS卫星个数
				delete	[]AX;
				delete	[]V;
				delete	[]VT;
				delete	[]VTP;
				delete	[]VTPV;

				delete	[]ll;
				delete	[]mm;
				delete	[]nn;
				delete	[]L;
				delete	[]A;
				delete	[]AT;
				delete	[]P;
				delete	[]ATP;
				delete	[]ATPA;
				delete	[]inv_ATPA;
				delete	[]ATPL;
				delete	[]result;
			}

		}
#endif
		}
		else
		{
			rcoor->X=0;
			rcoor->Y=0;
			rcoor->Z=0;
			rcoor->P1=0;
			rcoor->P2=0;
		}
		delete	[]ll;
		delete	[]mm;
		delete	[]nn;
		delete	[]L;
		delete	[]A;
		delete	[]AT;
		delete	[]P;
		delete	[]ATP;
		delete	[]ATPA;
		delete	[]inv_ATPA;
		delete	[]ATPL;
		delete	[]result;
		T=NN;
	//}while(index==1);
	//*n=NN;
	//*final_P=PP;
}

void CNDGNSS::spp_recei_coor_single(rp *rcoor,sp scoor,double wj[],int *n,double SR[],double *GDOP,double *PDOP)
{	
	double RMS=0.0;
	int jinxingcuchatichu=0;
	int NN=*n;							//传过来的gps/bds卫星个数;
	int T=NN;
	int i;									//为了进行循环;

	double X0,Y0,Z0;
	X0=rcoor->X;
	Y0=rcoor->Y;
	Z0=rcoor->Z;

	double	*ll=			new	double[T]();		//课本P57参数  等加以double	(*ll)[1]=	 new	double[T][1];
	double	*mm=			new	double[T]();
	double	*nn=			new	double[T]();
	double	*L=			new	double[T]();	
	double	*A=			new	double[T*4]();	//状态矩阵A;
	double	*AT=			new	double[4*T]();	//状态矩阵A的转置;
	double	*P=			new	double[T*T]();	//权矩阵P;              ()是对动态内存进行初始化
	double	*ATP=		new	double[4*T]();	//A的转置乘以P;
	double	*ATPA=		new	double[4*4]();	//A的转置乘以P乘以A;
	double	*inv_ATPA=	new	double[4*4]();	//(A的转置乘以P乘以A)的逆;
	double	*ATPL=		new	double[4]();		//A的转置乘以P乘以L;
	double	*result=		new	double[4]();		//(A的转置乘以P乘以A)乘以(A的转置乘以P乘以L)，(inv_ATPA)(ATPL);


	double	*AX=	new	double[T]();	//A乘以X;
	double  *V=		new	double[T]();	//V=AX-L
	double *VT=		new	double[1*T]();
	double *VTP=	new	double[1*T]();
	double *VTPV=	new	double[T*1]();
	///////////////////////////////////////////列法方程;


	if(NN>4)//rms有值;
	{
		//cout<<"系数矩阵B和L"<<endl;																	//☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀
		for(i=0;i<NN;i++)							
		{
			ll[i]=(scoor.X[i]-rcoor->X)/SR[i];
			mm[i]=(scoor.Y[i]-rcoor->Y)/SR[i];
			nn[i]=(scoor.Z[i]-rcoor->Z)/SR[i];
			A[i*4+0]=ll[i];
			A[i*4+1]=mm[i];
			A[i*4+2]=nn[i];
			A[i*4+3]=-1;
			//A[i*5+4]=0;								//初始化了就不需要了
			L[i]=SR[i]-wj[i];

			P[i*T+i]=1.0;	
			//printf("%8.3f%8.3f%8.3f%8.3f%8.3f%16.3f\n",A[i*5+0],A[i*5+1],A[i*5+2],A[i*5+3],A[i*5+4],L[i]);	//☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀☀


		}


		///////////////////////////////////////////通过函数的指针进行矩阵的运算，传出需要的矩阵;
		M_Tra(T,4,A,AT);							//矩阵转置	A的转置		传出AT;
		M_Mul(4,T,T,AT,P,ATP);						//矩阵相乘	AT乘P		传出ATP;
		M_Mul(4,T,4,ATP,A,ATPA);					//			ATP乘A		传出ATPA;
		M_Inv(4,ATPA,inv_ATPA);					//矩阵求逆	ATPA的逆		传出inv_ATPA;
		M_Mul(4,T,1,ATP,L,ATPL);					//			ATP乘L		传出ATPL;
		M_Mul(4,4,1,inv_ATPA,ATPL,result);			//			inv_ATPA乘ATPL传出result;

		//cout<<inv_ATPA[1]<<inv_ATPA[2]<<inv_ATPA[3]<<inv_ATPA[4]<<inv_ATPA[5]<<endl;
		//cout<<ATPL[1]<<ATPL[2]<<ATPL[3]<<ATPL[4]<<ATPL[5]<<endl;
		if(inv_ATPA!=NULL)
		{
			rcoor->X =result[0];
			rcoor->Y =result[1];
			rcoor->Z =result[2];
			rcoor->P=result[3];


			for(i=0;i<4;i++)
				*GDOP+=inv_ATPA[i*4+i];
			*GDOP=sqrt(*GDOP);
			for(i=0;i<3;i++)
				*PDOP+=inv_ATPA[i*4+i];
			*PDOP=sqrt(*PDOP);                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
		}
		else
		{
			rcoor->X=0;
			rcoor->Y=0;
			rcoor->Z=0;
			rcoor->P=0;

			//printf("这个历元数据无法求解!\n");
			//system("pause");
		}
	}
	delete	[]AX;
	delete	[]V;
	delete	[]VT;
	delete	[]VTP;
	delete	[]VTPV;

	delete	[]ll;
	delete	[]mm;
	delete	[]nn;
	delete	[]L;
	delete	[]A;
	delete	[]AT;
	delete	[]P;
	delete	[]ATP;
	delete	[]ATPA;
	delete	[]inv_ATPA;
	delete	[]ATPL;
	delete	[]result;
	*n=NN;
	//*final_P=PP;
}

//三系统;
void CNDGNSS::gps_bds_glo_coor(rp *rcoor,sp gps_coor,double gps_wj[],double GPS_SR[],sp bds_coor,double bds_wj[],double BDS_SR[],sp glo_coor,double glo_wj[],double GLO_SR[],int ALL_GB,int MM,int KK,int GG,double *GDOP,double *PDOP,double time)
{	
	//FILE *che	;
	//che=fopen("检测矩阵文件输出.txt","wb+");
	//int l = 5;									//观测矩阵是列数,5个未知数（接收机位置改正x+y+z+三个接收机钟差(P1,P2,P3)）;
	//传过来的gps/bds卫星个数;
	int T=ALL_GB;									//多系统定位总的卫星个数Totle，也就是行Row;
	int Column=6;									//未知数的个数(矩阵的列数)(比如单系统为4，双系统为5，三系统为6);
	int i,j;										//为了进行循环;

	//()是对动态内存进行初始化;
	double	*ll=		new	double[T]();			//课本P57参数  等加以double	(*ll)[1]=	 new	double[T][1];
	double	*mm=		new	double[T]();
	double	*nn=		new	double[T]();
	double	*L=			new	double[T]();	
	double	*A=			new	double[T*Column]();		//状态矩阵A;
	double	*AT=		new	double[Column*T]();		//状态矩阵A的转置;
	double	*P=			new	double[T*T]();			//权矩阵P;              
	double	*ATP=		new	double[Column*T]();		//A的转置乘以P;
	double	*ATPA=		new	double[Column*Column]();//A的转置乘以P乘以A;
	double	*inv_ATPA=	new	double[Column*Column]();//(A的转置乘以P乘以A)的逆;
	double	*ATPL=		new	double[Column]();		//A的转置乘以P乘以L;
	double	*result=	new	double[Column]();		//(A的转置乘以P乘以A)乘以(A的转置乘以P乘以L)，(inv_ATPA)(ATPL);

	///////////////////////////////////////////列法方程;
	for(i=0;i<MM;i++)							
	{
		ll[i]=(gps_coor.X[i]-rcoor->X)/GPS_SR[i];
		mm[i]=(gps_coor.Y[i]-rcoor->Y)/GPS_SR[i];
		nn[i]=(gps_coor.Z[i]-rcoor->Z)/GPS_SR[i];
		A[i*Column+0]=ll[i];
		A[i*Column+1]=mm[i];
		A[i*Column+2]=nn[i];
		A[i*Column+3]=-1;
		//A[i*Column+4]=0;							//初始化了就不需要了
		L[i]=GPS_SR[i]-gps_wj[i];
		P[i*T+i]=2.5;							//给GPS定的权，权改了，16.05.15
		//fprintf(m_fpche,"%15.10f %15.10f %15.10f %15.10f\n",A[i*Column+0],A[i*Column+1],A[i*Column+2],A[i*Column+3]);
		//fprintf(m_fpche, "%15.5f\n", L[i]);
	}
	for(j=MM;j<MM+KK;j++)
	{
		ll[j]=(bds_coor.X[j-MM]-rcoor->X)/BDS_SR[j-MM];
		mm[j]=(bds_coor.Y[j-MM]-rcoor->Y)/BDS_SR[j-MM];
		nn[j]=(bds_coor.Z[j-MM]-rcoor->Z)/BDS_SR[j-MM];
		A[j*Column+0]=ll[j];
		A[j*Column+1]=mm[j];
		A[j*Column+2]=nn[j];
		A[j*Column+4]=-1;
		//A[j*Column+3]=0;							//初始化了就不需要了;

		L[j]=BDS_SR[j-MM]-bds_wj[j-MM];
		P[j*T+j]=1;									//给BDS定的权
		//fprintf(m_fpche,"%15.5f %15.5f %15.5f %15.5f\n",A[j*Column+0],A[j*Column+1],A[j*Column+2],A[j*Column+4]);
		//fprintf(m_fpche,"%15.5f\n",L[j]);
	}
	for(j=MM+KK;j<ALL_GB;j++)
	{
		ll[j]=(glo_coor.X[j-MM-KK]-rcoor->X)/GLO_SR[j-MM-KK];
		mm[j]=(glo_coor.Y[j-MM-KK]-rcoor->Y)/GLO_SR[j-MM-KK];
		nn[j]=(glo_coor.Z[j-MM-KK]-rcoor->Z)/GLO_SR[j-MM-KK];
		A[j*Column+0]=ll[j];
		A[j*Column+1]=mm[j];
		A[j*Column+2]=nn[j];
		A[j*Column+5]=-1;

		L[j]=GLO_SR[j-MM-KK]-glo_wj[j-MM-KK];
		P[j*T+j]=1;									//给GLO定的权
	}

	//////////////////////////////////////////////////通过函数的指针进行矩阵的运算，传出需要的矩阵;

	M_Tra(T,Column,A,AT);							//矩阵转置	A的转置		传出AT;
	M_Mul(Column,T,T,AT,P,ATP);						//矩阵相乘	AT乘P		传出ATP;
	M_Mul(Column,T,Column,ATP,A,ATPA);				//			ATP乘A		传出ATPA;
	M_Inv(Column,ATPA,inv_ATPA);					//矩阵求逆	ATPA的逆		传出inv_ATPA;
	M_Mul(Column,T,1,ATP,L,ATPL);					//			ATP乘L		传出ATPL;
	M_Mul(Column,Column,1,inv_ATPA,ATPL,result);	//			inv_ATPA乘ATPL传出result;


	if(inv_ATPA!=NULL)
	{
		rcoor->X =result[0];
		rcoor->Y =result[1];
		rcoor->Z =result[2];
		rcoor->P1=result[3];
		rcoor->P2=result[4];
		rcoor->P3=result[5];
		for(i=0;i<Column;i++)
			*GDOP+=inv_ATPA[i*Column+i];
		*GDOP=sqrt(*GDOP);
		for(i=0;i<3;i++)
			*PDOP+=inv_ATPA[i*Column+i];
		*PDOP=sqrt(*PDOP);                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
	}
	else
	{
		rcoor->X=0;
		rcoor->Y=0;
		rcoor->Z=0;
		rcoor->P1=0;
		rcoor->P2=0;
		rcoor->P3=0;
		//	printf("这个历元数据无法求解!\n");
	}
	delete	[]ll;
	delete	[]mm;
	delete	[]nn;
	delete	[]L;
	delete	[]A;
	delete	[]AT;
	delete	[]P;
	delete	[]ATP;
	delete	[]ATPA;
	delete	[]inv_ATPA;
	delete	[]ATPL;
	delete	[]result;
	//fclose(che);
}
//双系统;
void CNDGNSS::recei_coor(rp *rcoor,sp gps_coor,double gps_wj[],double GPS_SR[],sp bds_coor,double bds_wj[],double BDS_SR[],int ALL_GB,int MM,int KK,double *GDOP,double *PDOP,double time)
{	
	//FILE *che	;
	//che=fopen("检测矩阵文件输出.txt","wb+");
	//int l = 5;									//观测矩阵是列数,5个未知数（接收机位置改正x+y+z+三个接收机钟差(P1,P2,P3)）;
	//传过来的gps/bds卫星个数;
	int T=ALL_GB;									//多系统定位总的卫星个数Totle，也就是行Row;
	int Column=5;									//未知数的个数(矩阵的列数)(比如单系统为4，双系统为5，三系统为6);
	int i,j;										//为了进行循环;

	//()是对动态内存进行初始化;
	double	*ll=		new	double[T]();			//课本P57参数  等加以double	(*ll)[1]=	 new	double[T][1];
	double	*mm=		new	double[T]();
	double	*nn=		new	double[T]();
	double	*L=			new	double[T]();	
	double	*A=			new	double[T*Column]();		//状态矩阵A;
	double	*AT=		new	double[Column*T]();		//状态矩阵A的转置;
	double	*P=			new	double[T*T]();			//权矩阵P;              
	double	*ATP=		new	double[Column*T]();		//A的转置乘以P;
	double	*ATPA=		new	double[Column*Column]();//A的转置乘以P乘以A;
	double	*inv_ATPA=	new	double[Column*Column]();//(A的转置乘以P乘以A)的逆;
	double	*ATPL=		new	double[Column]();		//A的转置乘以P乘以L;
	double	*result=	new	double[Column]();		//(A的转置乘以P乘以A)乘以(A的转置乘以P乘以L)，(inv_ATPA)(ATPL);

	///////////////////////////////////////////列法方程;
	for(i=0;i<MM;i++)							
	{
		ll[i]=(gps_coor.X[i]-rcoor->X)/GPS_SR[i];
		mm[i]=(gps_coor.Y[i]-rcoor->Y)/GPS_SR[i];
		nn[i]=(gps_coor.Z[i]-rcoor->Z)/GPS_SR[i];
		A[i*Column+0]=ll[i];
		A[i*Column+1]=mm[i];
		A[i*Column+2]=nn[i];
		A[i*Column+3]=-1;

		//A[i*Column+4]=0;							//初始化了就不需要了
		L[i]=GPS_SR[i]-gps_wj[i];
		P[i*T+i]=2.5;							//给GPS定的权，权改了，16.05.15
		//fprintf(m_fpche,"%15.10f %15.10f %15.10f %15.10f\n",A[i*Column+0],A[i*Column+1],A[i*Column+2],A[i*Column+3]);
		//fprintf(m_fpche, "%15.5f\n", L[i]);
	}
	for(j=MM;j<ALL_GB;j++)
	{
		ll[j]=(bds_coor.X[j-MM]-rcoor->X)/BDS_SR[j-MM];
		mm[j]=(bds_coor.Y[j-MM]-rcoor->Y)/BDS_SR[j-MM];
		nn[j]=(bds_coor.Z[j-MM]-rcoor->Z)/BDS_SR[j-MM];
		A[j*Column+0]=ll[j];
		A[j*Column+1]=mm[j];
		A[j*Column+2]=nn[j];
		A[j*Column+4]=-1;
		//A[j*Column+3]=0;							//初始化了就不需要了;

		L[j]=BDS_SR[j-MM]-bds_wj[j-MM];
		P[j*T+j]=1;									//给BDS定的权
		//fprintf(m_fpche,"%15.5f %15.5f %15.5f %15.5f\n",A[j*Column+0],A[j*Column+1],A[j*Column+2],A[j*Column+4]);
		//fprintf(m_fpche,"%15.5f\n",L[j]);
	}


	//////////////////////////////////////////////////通过函数的指针进行矩阵的运算，传出需要的矩阵;

	M_Tra(T,Column,A,AT);							//矩阵转置	A的转置		传出AT;
	M_Mul(Column,T,T,AT,P,ATP);						//矩阵相乘	AT乘P		传出ATP;
	M_Mul(Column,T,Column,ATP,A,ATPA);				//			ATP乘A		传出ATPA;
	M_Inv(Column,ATPA,inv_ATPA);					//矩阵求逆	ATPA的逆		传出inv_ATPA;
	M_Mul(Column,T,1,ATP,L,ATPL);					//			ATP乘L		传出ATPL;
	M_Mul(Column,Column,1,inv_ATPA,ATPL,result);	//			inv_ATPA乘ATPL传出result;


	if(inv_ATPA!=NULL)
	{
		rcoor->X =result[0];
		rcoor->Y =result[1];
		rcoor->Z =result[2];
		rcoor->P1=result[3];
		rcoor->P2=result[4];
		for(i=0;i<Column;i++)
			*GDOP+=inv_ATPA[i*Column+i];
		*GDOP=sqrt(*GDOP);
		for(i=0;i<3;i++)
			*PDOP+=inv_ATPA[i*Column+i];
		*PDOP=sqrt(*PDOP);                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
	}
	else
	{
		rcoor->X=0;
		rcoor->Y=0;
		rcoor->Z=0;
		rcoor->P1=0;
		rcoor->P2=0;
		//	printf("这个历元数据无法求解!\n");
	}
	delete	[]ll;
	delete	[]mm;
	delete	[]nn;
	delete	[]L;
	delete	[]A;
	delete	[]AT;
	delete	[]P;
	delete	[]ATP;
	delete	[]ATPA;
	delete	[]inv_ATPA;
	delete	[]ATPL;
	delete	[]result;
	//fclose(che);
}

//电离层双频改正;
int CNDGNSS::ion(double *wj,DATG dg[],int sta_num,int i,int gnss_type)//S_type卫星类型1为GPS，2为BDS
{
	if(gnss_type==1)
	{
		double f1=1575.42e6,f2=1227.6e6;
		if(dg[sta_num].data[i][0]!=NULL&&dg[sta_num].data[i][2]!=NULL)
			*wj=(dg[sta_num].data[i][0]-dg[sta_num].data[i][2]*f2*f2/(f1*f1))*f1*f1/(f1*f1-f2*f2);
		else if(dg[sta_num].data[i][0]!=NULL)
			*wj=dg[sta_num].data[i][0];
		else if(dg[sta_num].data[i][2]!=NULL)
			*wj=dg[sta_num].data[i][2];

	}
	if(gnss_type==2)
	{
		double f1=1561.1e6,f2=1207.14e6;
		if(dg[sta_num].data[i][0]!=NULL&&dg[sta_num].data[i][2]!=NULL)
			*wj=(dg[sta_num].data[i][0]-dg[sta_num].data[i][2]*f2*f2/(f1*f1))*f1*f1/(f1*f1-f2*f2);
		else if(dg[sta_num].data[i][0]!=NULL)
			*wj=dg[sta_num].data[i][0];
		else if(dg[sta_num].data[i][2]!=NULL)
			*wj=dg[sta_num].data[i][2];
	}
	return 0;
}
void CNDGNSS::GRID_CENTER_MODULE(DATG dg0[], IOFH ih[], BS_PR_CR BBPC[], int Bn[], int Bp[],  position1 m_pos[], BS_PR_CR CBPC[],int NO_JZZ)
{
	double BX[20]={0}, BBBY[20]={0}, BZ[20]={0};							    //基准站1坐标
	double CX=0, CY=0, CZ=0;                              //网格点坐标
	double B_C[20]={0};                        //网格点到基准点距离
	double s=0,sn[20]={0};
	double a[20]={0};
	int    NO_GC=18;                      //当网格变化时，网格点个数就要修改，四川北区总共13个网格点控制，加上两度的共17！！！！！！！！！注意
	//BS_PR_CR CBPC[100]={0};                        //网格点伪距改正值
	for (int i=0; i< NO_JZZ-1; i++){BX[i+1]=ih[i].xyz[0];BBBY[i+1]=ih[i].xyz[1];BZ[i+1]=ih[i].xyz[2];}//4个基准站数据分别给了BX,BY,BZ,1起算，三个基准站0,1,2

	for(int i=1;i<NO_GC+1;i++)                                    //32个网格点，从1起算
	{
		CX=m_pos[i].x;
		CY=m_pos[i].y;
		CZ=m_pos[i].z;
		s = 0;
		for (int nj=1;nj< NO_JZZ;nj++)                  //4基准站
		{
			B_C[nj]=sqrt(pow(BX[nj] - CX, 2) + pow(BBBY[nj] - CY, 2) + pow(BZ[nj] - CZ, 2));
			sn[nj]=1.0 / B_C[nj];
			s+=sn[nj];
		}
		for(int nj=1;nj< NO_JZZ;nj++)                   //4基准站
		{
			a[nj] = sn[nj] / s;
		}
		int nn = 0, pp = 0, k[30]={0};
		for ( k[1] = 0; k[1]<Bn[1]; k[1]++)						//主控站1GPS卫星数
		{
			for ( k[2] = 0; k[2]<Bn[2]; k[2]++)					//监测站2GPS卫星数
			{
				if (BBPC[1].G_PRN[k[1]] == BBPC[2].G_PRN[k[2]])
				{
					for ( k[3] = 0; k[3]<Bn[3]; k[3]++)			//监测站3GPS卫星数
					{
						if (BBPC[1].G_PRN[k[1]] == BBPC[3].G_PRN[k[3]])
						{
							for ( k[4] = 0; k[4]<Bn[4]; k[4]++)					//监测站4GPS卫星数
							{
								if (BBPC[1].G_PRN[k[1]] == BBPC[4].G_PRN[k[4]])
								{
									//for ( k[5] = 0; k[5]<Bn[5]; k[5]++)			//监测站5GPS卫星数
									//{
									//	if (BBPC[1].G_PRN[k[1]] == BBPC[5].G_PRN[k[5]])
									//	{
									//		for ( k[6] = 0; k[6]<Bn[6]; k[6]++)			//监测站6GPS卫星数
									//		{
									//			if (BBPC[1].G_PRN[k[1]] == BBPC[6].G_PRN[k[6]])
									//			{
									CBPC[m_pos[i].no].G_PRN[nn] = BBPC[1].G_PRN[k[1]];//反距离加权后的BPC除伪距改正项外，其他与主控站一致;
									for(int njjzz=1;njjzz< NO_JZZ;njjzz++){CBPC[m_pos[i].no].GPC[nn] += a[njjzz]*BBPC[njjzz].GPC[k[njjzz]];}//NO_JZZ个基准站

									nn++;
									break;
									//			}
									//		}
									//		break;
									//	}
									//}
									//break;
								}
							}
							break;
						}
					}
					break;
				}
			}
		}
		for ( k[1] = 0; k[1]<Bp[1]; k[1]++)						//主控站1BDS卫星数
		{
			for ( k[2] = 0; k[2]<Bp[2]; k[2]++)					//监测站2BDS卫星数
			{
				if (BBPC[1].C_PRN[k[1]] == BBPC[2].C_PRN[k[2]])
				{
					for ( k[3] = 0; k[3]<Bp[3]; k[3]++)			//监测站3BDS卫星数
					{
						if (BBPC[1].C_PRN[k[1]] == BBPC[3].C_PRN[k[3]])
						{
							for ( k[4] = 0; k[4]<Bp[4]; k[4]++)					//监测站4BDS卫星数
							{
								if (BBPC[1].C_PRN[k[1]] == BBPC[4].C_PRN[k[4]])
								{
									//for ( k[5] = 0; k[5]<Bp[5]; k[5]++)			//监测站5BDS卫星数
									//{
									//	if (BBPC[1].C_PRN[k[1]] == BBPC[5].C_PRN[k[5]])
									//	{
									//		for ( k[6] = 0; k[6]<Bp[6]; k[6]++)			//监测站6BDS卫星数
									//		{
									//			if (BBPC[1].C_PRN[k[1]] == BBPC[6].C_PRN[k[6]])
									//			{
									CBPC[m_pos[i].no].C_PRN[pp] = BBPC[1].C_PRN[k[1]];//反距离加权后的BPC除伪距改正项外，其他与主控站一致;
									for(int njjzz=1;njjzz< NO_JZZ;njjzz++){CBPC[m_pos[i].no].CPC[pp] += a[njjzz]*BBPC[njjzz].CPC[k[njjzz]];}

									pp++;
									break;
									//			}
									//		}
									//		break;
									//	}
									//}
									//break;
								}
							}
							break;
						}
					}
					break;
				}
			}
		}
		//PP[i]=pp;
		//NN[i]=nn;
		CBPC[m_pos[i].no].C_num=pp;
		CBPC[m_pos[i].no].G_num=nn;

		//for (int k1 = 0; k1<B1p; k1++)						//主控站BDS卫星数
		//{
		//	for (int k2 = 0; k2<B2p; k2++)					//监测站1BDS卫星数
		//	{
		//		if (B1BPC.C_PRN[k1] == B2BPC.C_PRN[k2])
		//		{
		//			for (int k3 = 0; k3<B3p; k3++)			//监测站2BDS卫星数
		//			{
		//				if (B1BPC.C_PRN[k1] == B3BPC.C_PRN[k3])
		//				{

		//					CBPC[i].C_PRN[pp] = B1BPC.C_PRN[k1];
		//					CBPC[i].CPC[pp] = a1*B1BPC.CPC[k1] + a2*B2BPC.CPC[k2] + a3*B3BPC.CPC[k3];
		//					pp++;
		//					break;
		//				}
		//			}
		//			break;
		//		}
		//	}
		//}

	}
	fprintf(BPC_fil, "%5d\n",int(dg0[0].tg.second));
	for (int wgd=1; wgd< NO_GC+1; wgd++)      //13个网格点，从1起算              
	{
		fprintf(BPC_fil, "CBPC%3d %5d G:%3d  C:%3d\n", m_pos[wgd].no,int(dg0[0].tg.second), CBPC[m_pos[wgd].no].G_num,CBPC[m_pos[wgd].no].C_num);
		for (int u = 0; u < CBPC[m_pos[wgd].no].G_num; u++)
			fprintf(BPC_fil, "CBPC%3d G%3d,%5d,%10.3f\n",m_pos[wgd].no,CBPC[m_pos[wgd].no].G_PRN[u],int(dg0[0].tg.second), CBPC[m_pos[wgd].no].GPC[u]);
		for (int r = 0; r < CBPC[m_pos[wgd].no].C_num; r++)
			fprintf(BPC_fil, "CBPC%3d C%3d,%5d,%10.3f\n", m_pos[wgd].no,CBPC[m_pos[wgd].no].C_PRN[r],int(dg0[0].tg.second), CBPC[m_pos[wgd].no].CPC[r]);
	}
}


void CNDGNSS::GRID_MOVING_POS_MODULE(double  xyz2ldz[],position1 m_pos[],BS_PR_CR CBPC[],DATG dg0[], GEPH geph[MAXPRN_NUM], rp &rcoor2, Sate_NUM &sate_num, int igc)
{
	double	delt = 1;								//do...while()限制条件中的接收机X坐标迭代控制条件
	double	GDOP2 = 0, PDOP2 = 0;
	DATG dg[5] = { 0 };
	int i = 0;
	dg[i + 1] = dg0[0];
	BS_PR_CR BPC;
	int M1gps_num = 0, M1bds_num = 0, M1glo_num = 0;	//<流动站1/2>GPS可见卫星数

	for (int ii = 0; ii<dg[1].nsat; ii++)
	{
		if (dg[1].prn[ii] <= 33)
			M1gps_num++;
		if (dg[1].prn[ii] >= 38 && dg[1].prn[ii] <= 61)
			M1glo_num++;
		if (dg[1].prn[ii] >= 161 && dg[1].prn[ii] <= 197)
			M1bds_num++;
	}


	double	C1X, C1Y, C1Z;							//网格点1坐标
	double	C2X, C2Y, C2Z;							//网格点2坐标
	double	C3X, C3Y, C3Z;							//网格点3坐标
	double	C4X, C4Y, C4Z;							//网格点4坐标
	double MX, MY, MZ;                              //流动站坐标
	double C1_M, C2_M, C3_M, C4_M;                  //流动站与中心点间距离
	double s1, s2, s3, s4, s;
	double a1, a2, a3, a4;
	//----------------------------------------------------------------------------------------------------------
	//这里因为是车载，所以流动站一直在变，那么如果流动站有坐标，就用流动站坐标到各基准站的距离，如果流动站坐标为0，就用监测站坐标，一般流动站第一次坐标为0，以后都会有值，为上一次的解得的值;
	IOFH ih3[4] = { 0 };
	//01MNZU
	//02MNYG
	//03ANYE

	for (int i = 0; i<4; i++)
	{
		ih3[i].ntype = 5;
		CString strObs_type = _T("C1 L1 P2 L2 B3");
		memcpy(ih3[i].type, strObs_type, strObs_type.GetLength() + 1);

	}
	int nl=3,nh=3;//3行，3列
	ih3[0].xyz[0] = m_pos[igc-nl*nh].x;
	ih3[0].xyz[1] = m_pos[igc-nl*nh].y;
	ih3[0].xyz[2] = m_pos[igc-nl*nh].z;
	ih3[1].xyz[0] = m_pos[igc-nl*nh+1].x;
	ih3[1].xyz[1] = m_pos[igc-nl*nh+1].y;
	ih3[1].xyz[2] = m_pos[igc-nl*nh+1].z;
	ih3[2].xyz[0] = m_pos[igc-nl*(nh-1)].x;
	ih3[2].xyz[1] = m_pos[igc-nl*(nh-1)].y;
	ih3[2].xyz[2] = m_pos[igc-nl*(nh-1)].z;
	ih3[3].xyz[0] = m_pos[igc-nl*(nh-1)+1].x;
	ih3[3].xyz[1] = m_pos[igc-nl*(nh-1)+1].y;
	ih3[3].xyz[2] = m_pos[igc-nl*(nh-1)+1].z;


	MX = xyz2ldz[0];
	MY = xyz2ldz[1];
	MZ = xyz2ldz[2];

	C1X = ih3[0].xyz[0];
	C1Y = ih3[0].xyz[1];
	C1Z = ih3[0].xyz[2];
	C2X = ih3[1].xyz[0];
	C2Y = ih3[1].xyz[1];
	C2Z = ih3[1].xyz[2];
	C3X = ih3[2].xyz[0];
	C3Y = ih3[2].xyz[1];
	C3Z = ih3[2].xyz[2];
	C4X = ih3[3].xyz[0];
	C4Y = ih3[3].xyz[1];
	C4Z = ih3[3].xyz[2];

	C1_M = sqrt(pow(C1X - MX, 2) + pow(C1Y - MY, 2) + pow(C1Z - MZ, 2));
	C2_M = sqrt(pow(C2X - MX, 2) + pow(C2Y - MY, 2) + pow(C2Z - MZ, 2));
	C3_M = sqrt(pow(C3X - MX, 2) + pow(C3Y - MY, 2) + pow(C3Z - MZ, 2));
	C4_M = sqrt(pow(C4X - MX, 2) + pow(C4Y - MY, 2) + pow(C4Z - MZ, 2));

	s1 = 1.0 / C1_M; s2 = 1.0 / C2_M; s3 = 1.0 / C3_M; s4 = 1.0 / C4_M;
	s = s1 + s2 + s3 + s4;
	a1 = s1 / s; a2 = s2 / s; a3 = s3 / s; a4 = s4 / s;
	//------------------------------------------------------------------------------------------------------------
	//------------------------------------------------------------------------------------------------------------



	int nn = 0, pp = 0;
	for (int k1 = 0; k1<CBPC[igc-nl*nh].G_num; k1++)						//左上点GPS卫星数igc-nl*nh,NN[]->CBPC[].G_num
	{
		for (int k2 = 0; k2<CBPC[igc-nl*nh+1].G_num; k2++)					//右上点GPS卫星数igc-nl*nh+1
		{
			if (CBPC[igc-nl*nh].G_PRN[k1] == CBPC[igc-nl*nh+1].G_PRN[k2])
			{
				for (int k3 = 0; k3<CBPC[igc-nl*(nh-1)].G_num; k3++)			//左下点GPS卫星数igc-nl*(nh-1)
				{
					if (CBPC[igc-nl*nh].G_PRN[k1] == CBPC[igc-nl*(nh-1)].G_PRN[k3])
					{
						for (int k4 = 0; k3<CBPC[igc-nl*(nh-1)+1].G_num; k4++)    //右下点GPS卫星数igc-nl*(nh-1)+1
						{
							if (CBPC[igc-nl*nh].G_PRN[k1] == CBPC[igc-nl*(nh-1)+1].G_PRN[k4])
							{
								BPC.G_PRN[nn] = CBPC[igc-nl*nh].G_PRN[k1];//反距离加权后的BPC除伪距改正项外，其他与主控站一致;
								BPC.GPC[nn] = a1*CBPC[igc-nl*nh].GPC[k1] + a2*CBPC[igc-nl*nh+1].GPC[k2] + a3*CBPC[igc-nl*(nh-1)].GPC[k3] + a4*CBPC[igc-nl*(nh-1)+1].GPC[k4];
								nn++;
								break;
							}
						}
						break;
					}
				}
				break;
			}
		}
	}
	for (int k1 = 0; k1<CBPC[igc-nl*nh].C_num; k1++)						//左上BDS卫星数igc-nl*nh
	{
		for (int k2 = 0; k2<CBPC[igc-nl*nh+1].C_num; k2++)					//右上点3BDS卫星数igc-nl*nh+1
		{
			if (CBPC[igc-nl*nh].C_PRN[k1] == CBPC[igc-nl*nh+1].C_PRN[k2])
			{
				for (int k3 = 0; k3<CBPC[igc-nl*(nh-1)].C_num; k3++)			//左下点7BDS卫星数igc-nl*(nh-1)
				{
					if (CBPC[igc-nl*nh].C_PRN[k1] == CBPC[igc-nl*(nh-1)].C_PRN[k3])
					{
						for (int k4 = 0; k3<CBPC[igc-nl*(nh-1)+1].C_num; k4++)    //右下点8BDS卫星数igc-nl*(nh-1)+1
						{
							if (CBPC[igc-nl*nh].C_PRN[k1] == CBPC[igc-nl*(nh-1)+1].C_PRN[k4])
							{
								BPC.C_PRN[pp] = CBPC[igc-nl*nh].C_PRN[k1];
								BPC.CPC[pp] = a1*CBPC[igc-nl*nh].CPC[k1] + a2*CBPC[igc-nl*nh+1].CPC[k2] + a3*CBPC[igc-nl*(nh-1)].CPC[k3] + a4*CBPC[igc-nl*(nh-1)+1].CPC[k4];
								pp++;
								break;
							}
						}
						break;
					}
				}
				break;
			}
		}
	}




	/************▼流动站1  dg[1]计算▼↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/

	double	M2X0, M2Y0, M2Z0;							//流动站初始坐标;
	double	M2g_swj, M2g_R, M2b_swj, M2b_R;
	double	M2G_XK, M2G_YK, M2G_ZK, M2B_XK, M2B_YK, M2B_ZK;	//初始坐标;
	int		MM2, KK2, ALL_GB2;
	//rp		rcoor2={0};
	rcoor2.X = xyz2ldz[0];
	rcoor2.Y = xyz2ldz[1];
	rcoor2.Z = xyz2ldz[2];


	int xunhuan = 0;
	do		//最多循环10次跳出，代替do。。。。while
	{ 

		if( xunhuan>14)	{break;}		//最多循环10次跳出，代替do。。。。while
		xunhuan++;
		double	M2gps_wj[32] = { 0 }, M2GPS_SR[32] = { 0 };	//流动站解算的gps伪距&近似距离——存储值;
		double	M2bds_wj[35] = { 0 }, M2BDS_SR[35] = { 0 };	//流动站解算的bds伪距&近似距离——存储值;
		int		M2GPRN[32] = { 0 };						//流动站gpsPRN号——存储值;
		int		M2BPRN[35] = { 0 };						//流动站bdsPRN号——存储值;
		sp		M2gps_coor = { 0 }, M2bds_coor = { 0 };		//流动站解算的gps与bds的卫星坐标——存储值;

		double	M2_gps_wj[32] = { 0 }, M2_GPS_SR[32] = { 0 };//流动站最终解算;
		double	M2_bds_wj[35] = { 0 }, M2_BDS_SR[35] = { 0 };//流动站最终解算;
		int		M2_GPRN[32] = { 0 };					//流动站最终解算;
		int		M2_BPRN[35] = { 0 };					//流动站最终解算;
		sp		M2_gps_coor = { 0 }, M2_bds_coor = { 0 };	//流动站最终解算;


		double check2_gps[32] = { 0 }, check2_bds[35] = { 0 };//检测伪距改正输出;
		int	m2 = 0, k2 = 0;								//循环回代置零;
		M2X0 = rcoor2.X;								//用于循环回代;
		M2Y0 = rcoor2.Y;
		M2Z0 = rcoor2.Z;

		for (int ii = 0; ii<M1gps_num; ii++)				//基于流动站计算卫星位置及伪距&卫地距;
		{
			M2g_swj = 0, M2g_R = 0;
			M2G_XK = 0, M2G_YK = 0, M2G_ZK = 0;
			GNSS_POS_MODULE(geph, dg, 1, M2X0, M2Y0, M2Z0, &M2g_swj, &M2g_R, &M2G_XK, &M2G_YK, &M2G_ZK, ii, 1);//dg后面的参数为站号,为了配合dg【】中的号;
			if (M2g_swj != 0 && M2g_R != 0)
			{
				M2gps_wj[m2] = M2g_swj;
				M2GPS_SR[m2] = M2g_R;
				M2GPRN[m2] = dg[1].prn[ii];
				M2gps_coor.X[m2] = M2G_XK;
				M2gps_coor.Y[m2] = M2G_YK;
				M2gps_coor.Z[m2] = M2G_ZK;

				check2_gps[m2] = M2g_R - M2g_swj;					//检测改正值正确与否,与BDS的改正值对比,注意：检测时要加入卫星钟差，以使对比与BDS的改正值是否一致,正确的应该和BDS是一致的;
				m2++;											//m为可利用GPS卫星数目
			}
		}
		for (int ii = M1gps_num + M1glo_num; ii<dg[1].nsat; ii++)		//基于流动站计算卫星位置及伪距&卫地距;
		{
			M2b_swj = 0, M2b_R = 0;
			M2B_XK = 0, M2B_YK = 0, M2B_ZK = 0;
			GNSS_POS_MODULE(geph, dg, 1, M2X0, M2Y0, M2Z0, &M2b_swj, &M2b_R, &M2B_XK, &M2B_YK, &M2B_ZK, ii, 2);//dg后面的参数为站号,为了配合dg【】中的号;
			if (M2b_swj != 0 && M2b_R != 0)
			{
				M2bds_wj[k2] = M2b_swj;
				M2BDS_SR[k2] = M2b_R;
				M2BPRN[k2] = dg[1].prn[ii];
				M2bds_coor.X[k2] = M2B_XK;
				M2bds_coor.Y[k2] = M2B_YK;
				M2bds_coor.Z[k2] = M2B_ZK;

				check2_bds[k2] = M2b_R - M2b_swj;			//检测改正值正确与否,与GPS的改正值对比,注意：检测时要加入卫星钟差，以使对比与GPS的改正值是否一致,正确的应该和GPS是一致的;
				k2++;								//m为可利用GPS卫星数目
			}
		}

		/********▼匹配伪距改正数▼********/;
		int mm2 = 0, kk2 = 0;							//该历元中流动站和改正数相匹配的数;
		for (int ii = 0; ii<m2; ii++)				//匹配从3个基准站传过来的通过反距离加权后的GPS伪距改正值;
		{
			for (int jj = 0; jj<nn; jj++)
			{
				//if (M2GPRN[ii]==BPC.G_PRN[jj]&&BPC.C_PRN[jj]!=bad_BPRN[0]&&BPC.C_PRN[jj]!=bad_BPRN[1]&&BPC.C_PRN[jj]!=bad_BPRN[2]&&BPC.C_PRN[jj]!=bad_BPRN[3]&&BPC.C_PRN[jj]!=bad_BPRN[4])
				if (M2GPRN[ii] == BPC.G_PRN[jj])
				{
					M2_gps_wj[mm2] = M2gps_wj[ii] + BPC.GPC[jj];
					M2_GPS_SR[mm2] = M2GPS_SR[ii];
					M2_GPRN[mm2] = M2GPRN[ii];
					M2_gps_coor.X[mm2] = M2gps_coor.X[ii];
					M2_gps_coor.Y[mm2] = M2gps_coor.Y[ii];
					M2_gps_coor.Z[mm2] = M2gps_coor.Z[ii];
					mm2++;
					break;
				}
			}
		}
		for (int ii = 0; ii<k2; ii++)				//匹配从3个基准站传过来的的通过反距离加权后的BDS伪距改正值;
		{
			for (int jj = 0; jj<pp; jj++)
			{
				//if (M2BPRN[ii]==BPC.C_PRN[jj]&&BPC.C_PRN[jj]!=bad_BPRN[0]&&BPC.C_PRN[jj]!=bad_BPRN[1]&&BPC.C_PRN[jj]!=bad_BPRN[2]&&BPC.C_PRN[jj]!=bad_BPRN[3]&&BPC.C_PRN[jj]!=bad_BPRN[4])
				if (M2BPRN[ii] == BPC.C_PRN[jj])
				{
					M2_bds_wj[kk2] = M2bds_wj[ii] + BPC.CPC[jj];
					M2_BDS_SR[kk2] = M2BDS_SR[ii];
					M2_BPRN[kk2] = M2BPRN[ii];
					M2_bds_coor.X[kk2] = M2bds_coor.X[ii];
					M2_bds_coor.Y[kk2] = M2bds_coor.Y[ii];
					M2_bds_coor.Z[kk2] = M2bds_coor.Z[ii];
					kk2++;
					break;
				}
			}
		}

		/************▼定位解算▼↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
		MM2 = mm2, KK2 = kk2;
		ALL_GB2 = MM2 + KK2;
		if (ALL_GB2 >= 5 && MM2>2 && KK2>2)
		{
			recei_coor(&rcoor2, M2_gps_coor, M2_gps_wj, M2_GPS_SR, M2_bds_coor, M2_bds_wj, M2_BDS_SR, ALL_GB2, MM2, KK2, &GDOP2, &PDOP2, dg[1].tg.second);//计算接收机坐标,返回位置的改正数rcoor.X、rcoor.Y、rcoor.Z;
			if (rcoor2.X != 0 && rcoor2.Y != 0 && rcoor2.Z != 0)
			{
				rcoor2.X = rcoor2.X + M2X0;			//新的接收机坐标=改正数+初值，下面判断，如果delt>0.001的话，返回do，将rcoor.X重新作为初值，循环计算到delt<0.001;
				rcoor2.Y = rcoor2.Y + M2Y0;
				rcoor2.Z = rcoor2.Z + M2Z0;
				//delt = rcoor2.X - M2X0;
				delt = sqrt(pow(rcoor2.X - M2X0,2.0)+pow(rcoor2.Y - M2Y0,2.0)+pow(rcoor2.Z - M2Z0,2.0));

				if (fabs(delt)<0.00001)
					break;
			}
			else
			{
				rcoor2.X = 0;
				rcoor2.Y = 0;
				rcoor2.Z = 0;
				rcoor2.P1 = 0;
				rcoor2.P2 = 0;
				break;
			}
		}
		else
		{
			rcoor2.X = 0;
			rcoor2.Y = 0;
			rcoor2.Z = 0;
			rcoor2.P1 = 0;
			rcoor2.P2 = 0;
			break;
		}
		//if (rcoor2.X!=0&&fabs(delt)<0.00001)
		//	break;
	}while(1);

	if (rcoor2.X != 0 && MM2 != 0 && KK2 != 0)
	{
		sate_num.KK2 = KK2;
		sate_num.MM2 = MM2;
		sate_num.ALL_GB2 = ALL_GB2;
		sate_num.delX2 = rcoor2.X;
		sate_num.delY2 = rcoor2.Y;
		sate_num.delZ2 = rcoor2.Z;
		sate_num.M2_P1 = rcoor2.P1;
		sate_num.M2_P2 = rcoor2.P2;
		sate_num.GDOP2 = GDOP2;
		sate_num.PDOP2 = PDOP2;
	}


}

void CNDGNSS::GRID_MOVING_POS_MODULE_RAIM(double  xyz2ldz[],position1 m_pos[],BS_PR_CR CBPC[],DATG dg0[], GEPH geph[MAXPRN_NUM], rp &rcoor2, Sate_NUM &sate_num, int igc)
{
	double	delt = 1;								//do...while()限制条件中的接收机X坐标迭代控制条件
	double	GDOP2 = 0, PDOP2 = 0;
	DATG dg[5] = { 0 };
	//int i = 0;
	dg[1] = dg0[0];
	BS_PR_CR BPC;
	int M1gps_num = 0, M1bds_num = 0, M1glo_num = 0;	//<流动站1/2>GPS可见卫星数

	for (int ii = 0; ii<dg[1].nsat; ii++)
	{
		if (dg[1].prn[ii] <= 33)
			M1gps_num++;
		if (dg[1].prn[ii] >= 38 && dg[1].prn[ii] <= 61)
			M1glo_num++;
		if (dg[1].prn[ii] >= 161 && dg[1].prn[ii] <= 197)
			M1bds_num++;
	}


	double	C1X, C1Y, C1Z;							//网格点1坐标
	double	C2X, C2Y, C2Z;							//网格点2坐标
	double	C3X, C3Y, C3Z;							//网格点3坐标
	double	C4X, C4Y, C4Z;							//网格点4坐标
	double MX, MY, MZ;                              //流动站坐标
	double C1_M, C2_M, C3_M, C4_M;                  //流动站与中心点间距离
	double s1, s2, s3, s4, s;
	double a1, a2, a3, a4;
	//----------------------------------------------------------------------------------------------------------
	//这里因为是车载，所以流动站一直在变，那么如果流动站有坐标，就用流动站坐标到各基准站的距离，如果流动站坐标为0，就用监测站坐标，一般流动站第一次坐标为0，以后都会有值，为上一次的解得的值;
	IOFH ih3[4] = { 0 };
	//01MNZU
	//02MNYG
	//03ANYE

	for (int i = 0; i<4; i++)
	{
		ih3[i].ntype = 5;
		CString strObs_type = _T("C1 L1 P2 L2 B3");
		memcpy(ih3[i].type, strObs_type, strObs_type.GetLength() + 1);

	}
	int nl=3,nh=3;//3行，3列
	ih3[0].xyz[0] = m_pos[igc-nl*nh].x;
	ih3[0].xyz[1] = m_pos[igc-nl*nh].y;
	ih3[0].xyz[2] = m_pos[igc-nl*nh].z;
	ih3[1].xyz[0] = m_pos[igc-nl*nh+1].x;
	ih3[1].xyz[1] = m_pos[igc-nl*nh+1].y;
	ih3[1].xyz[2] = m_pos[igc-nl*nh+1].z;
	ih3[2].xyz[0] = m_pos[igc-nl*(nh-1)].x;
	ih3[2].xyz[1] = m_pos[igc-nl*(nh-1)].y;
	ih3[2].xyz[2] = m_pos[igc-nl*(nh-1)].z;
	ih3[3].xyz[0] = m_pos[igc-nl*(nh-1)+1].x;
	ih3[3].xyz[1] = m_pos[igc-nl*(nh-1)+1].y;
	ih3[3].xyz[2] = m_pos[igc-nl*(nh-1)+1].z;


	MX = xyz2ldz[0];
	MY = xyz2ldz[1];
	MZ = xyz2ldz[2];

	C1X = ih3[0].xyz[0];
	C1Y = ih3[0].xyz[1];
	C1Z = ih3[0].xyz[2];
	C2X = ih3[1].xyz[0];
	C2Y = ih3[1].xyz[1];
	C2Z = ih3[1].xyz[2];
	C3X = ih3[2].xyz[0];
	C3Y = ih3[2].xyz[1];
	C3Z = ih3[2].xyz[2];
	C4X = ih3[3].xyz[0];
	C4Y = ih3[3].xyz[1];
	C4Z = ih3[3].xyz[2];

	C1_M = sqrt(pow(C1X - MX, 2) + pow(C1Y - MY, 2) + pow(C1Z - MZ, 2));
	C2_M = sqrt(pow(C2X - MX, 2) + pow(C2Y - MY, 2) + pow(C2Z - MZ, 2));
	C3_M = sqrt(pow(C3X - MX, 2) + pow(C3Y - MY, 2) + pow(C3Z - MZ, 2));
	C4_M = sqrt(pow(C4X - MX, 2) + pow(C4Y - MY, 2) + pow(C4Z - MZ, 2));

	s1 = 1.0 / C1_M; s2 = 1.0 / C2_M; s3 = 1.0 / C3_M; s4 = 1.0 / C4_M;
	s = s1 + s2 + s3 + s4;
	a1 = s1 / s; a2 = s2 / s; a3 = s3 / s; a4 = s4 / s;
	//------------------------------------------------------------------------------------------------------------
	//------------------------------------------------------------------------------------------------------------



	int nn1 = 0, pp = 0;
	for (int k1 = 0; k1<CBPC[igc-nl*nh].G_num; k1++)						//左上点GPS卫星数igc-nl*nh,NN[]->CBPC[].G_num
	{
		for (int k2 = 0; k2<CBPC[igc-nl*nh+1].G_num; k2++)					//右上点GPS卫星数igc-nl*nh+1
		{
			if (CBPC[igc-nl*nh].G_PRN[k1] == CBPC[igc-nl*nh+1].G_PRN[k2])
			{
				for (int k3 = 0; k3<CBPC[igc-nl*(nh-1)].G_num; k3++)			//左下点GPS卫星数igc-nl*(nh-1)
				{
					if (CBPC[igc-nl*nh].G_PRN[k1] == CBPC[igc-nl*(nh-1)].G_PRN[k3])
					{
						for (int k4 = 0; k3<CBPC[igc-nl*(nh-1)+1].G_num; k4++)    //右下点GPS卫星数igc-nl*(nh-1)+1
						{
							if (CBPC[igc-nl*nh].G_PRN[k1] == CBPC[igc-nl*(nh-1)+1].G_PRN[k4])
							{
								BPC.G_PRN[nn1] = CBPC[igc-nl*nh].G_PRN[k1];//反距离加权后的BPC除伪距改正项外，其他与主控站一致;
								BPC.GPC[nn1] = a1*CBPC[igc-nl*nh].GPC[k1] + a2*CBPC[igc-nl*nh+1].GPC[k2] + a3*CBPC[igc-nl*(nh-1)].GPC[k3] + a4*CBPC[igc-nl*(nh-1)+1].GPC[k4];
								nn1++;
								break;
							}
						}
						break;
					}
				}
				break;
			}
		}
	}
	for (int k1 = 0; k1<CBPC[igc-nl*nh].C_num; k1++)						//左上BDS卫星数igc-nl*nh
	{
		for (int k2 = 0; k2<CBPC[igc-nl*nh+1].C_num; k2++)					//右上点3BDS卫星数igc-nl*nh+1
		{
			if (CBPC[igc-nl*nh].C_PRN[k1] == CBPC[igc-nl*nh+1].C_PRN[k2])
			{
				for (int k3 = 0; k3<CBPC[igc-nl*(nh-1)].C_num; k3++)			//左下点7BDS卫星数igc-nl*(nh-1)
				{
					if (CBPC[igc-nl*nh].C_PRN[k1] == CBPC[igc-nl*(nh-1)].C_PRN[k3])
					{
						for (int k4 = 0; k3<CBPC[igc-nl*(nh-1)+1].C_num; k4++)    //右下点8BDS卫星数igc-nl*(nh-1)+1
						{
							if (CBPC[igc-nl*nh].C_PRN[k1] == CBPC[igc-nl*(nh-1)+1].C_PRN[k4])
							{
								BPC.C_PRN[pp] = CBPC[igc-nl*nh].C_PRN[k1];
								BPC.CPC[pp] = a1*CBPC[igc-nl*nh].CPC[k1] + a2*CBPC[igc-nl*nh+1].CPC[k2] + a3*CBPC[igc-nl*(nh-1)].CPC[k3] + a4*CBPC[igc-nl*(nh-1)+1].CPC[k4];
								pp++;
								break;
							}
						}
						break;
					}
				}
				break;
			}
		}
	}




	/************▼流动站1  dg[1]计算▼↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/

	double	M2X0, M2Y0, M2Z0;							//流动站初始坐标;
	double	M2g_swj, M2g_R, M2b_swj, M2b_R;
	double	M2G_XK, M2G_YK, M2G_ZK, M2B_XK, M2B_YK, M2B_ZK;	//初始坐标;
	int		MM2, KK2, ALL_GB2;
	//rp		rcoor2={0};
	rcoor2.X = xyz2ldz[0];
	rcoor2.Y = xyz2ldz[1];
	rcoor2.Z = xyz2ldz[2];

	double	M2gps_wj[32] = { 0 }, M2GPS_SR[32] = { 0 };	//流动站解算的gps伪距&近似距离——存储值;
	double	M2bds_wj[35] = { 0 }, M2BDS_SR[35] = { 0 };	//流动站解算的bds伪距&近似距离——存储值;
	int		M2GPRN[32] = { 0 };						//流动站gpsPRN号——存储值;
	int		M2BPRN[35] = { 0 };						//流动站bdsPRN号——存储值;
	sp		M2gps_coor = { 0 }, M2bds_coor = { 0 };		//流动站解算的gps与bds的卫星坐标——存储值;

	double	M2_gps_wj[32] = { 0 }, M2_GPS_SR[32] = { 0 };//流动站最终解算;
	double	M2_bds_wj[35] = { 0 }, M2_BDS_SR[35] = { 0 };//流动站最终解算;
	int		M2_GPRN[32] = { 0 };					//流动站最终解算;
	int		M2_BPRN[35] = { 0 };					//流动站最终解算;
	sp		M2_gps_coor = { 0 }, M2_bds_coor = { 0 };	//流动站最终解算;

	double check2_gps[32] = { 0 }, check2_bds[35] = { 0 };//检测伪距改正输出;

	int xunhuan = 0;
	do		//最多循环10次跳出，代替do。。。。while
	{ 

		if( xunhuan>14)	{break;}		//最多循环10次跳出，代替do。。。。while
		xunhuan++;
		int	m2 = 0, k2 = 0;								//循环回代置零;
		M2X0 = rcoor2.X;								//用于循环回代;
		M2Y0 = rcoor2.Y;
		M2Z0 = rcoor2.Z;

		for (int ii = 0; ii<M1gps_num; ii++)				//基于流动站计算卫星位置及伪距&卫地距;
		{
			M2g_swj = 0, M2g_R = 0;
			M2G_XK = 0, M2G_YK = 0, M2G_ZK = 0;
			GNSS_POS_MODULE(geph, dg, 1, M2X0, M2Y0, M2Z0, &M2g_swj, &M2g_R, &M2G_XK, &M2G_YK, &M2G_ZK, ii, 1);//dg后面的参数为站号,为了配合dg【】中的号;
			if (M2g_swj != 0 && M2g_R != 0)
			{
				M2gps_wj[m2] = M2g_swj;
				M2GPS_SR[m2] = M2g_R;
				M2GPRN[m2] = dg[1].prn[ii];
				M2gps_coor.X[m2] = M2G_XK;
				M2gps_coor.Y[m2] = M2G_YK;
				M2gps_coor.Z[m2] = M2G_ZK;

				check2_gps[m2] = M2g_R - M2g_swj;					//检测改正值正确与否,与BDS的改正值对比,注意：检测时要加入卫星钟差，以使对比与BDS的改正值是否一致,正确的应该和BDS是一致的;
				m2++;											//m为可利用GPS卫星数目
			}
		}
		for (int ii = M1gps_num + M1glo_num; ii<dg[1].nsat; ii++)		//基于流动站计算卫星位置及伪距&卫地距;
		{
			M2b_swj = 0, M2b_R = 0;
			M2B_XK = 0, M2B_YK = 0, M2B_ZK = 0;
			GNSS_POS_MODULE(geph, dg, 1, M2X0, M2Y0, M2Z0, &M2b_swj, &M2b_R, &M2B_XK, &M2B_YK, &M2B_ZK, ii, 2);//dg后面的参数为站号,为了配合dg【】中的号;
			if (M2b_swj != 0 && M2b_R != 0)
			{
				M2bds_wj[k2] = M2b_swj;
				M2BDS_SR[k2] = M2b_R;
				M2BPRN[k2] = dg[1].prn[ii];
				M2bds_coor.X[k2] = M2B_XK;
				M2bds_coor.Y[k2] = M2B_YK;
				M2bds_coor.Z[k2] = M2B_ZK;

				check2_bds[k2] = M2b_R - M2b_swj;			//检测改正值正确与否,与GPS的改正值对比,注意：检测时要加入卫星钟差，以使对比与GPS的改正值是否一致,正确的应该和GPS是一致的;
				k2++;								//m为可利用GPS卫星数目
			}
		}

		/********▼匹配伪距改正数▼********/;
		int mm2 = 0, kk2 = 0;							//该历元中流动站和改正数相匹配的数;
		for (int ii = 0; ii<m2; ii++)				//匹配从3个基准站传过来的通过反距离加权后的GPS伪距改正值;
		{
			for (int jj = 0; jj<nn1; jj++)
			{
				//if (M2GPRN[ii]==BPC.G_PRN[jj]&&BPC.C_PRN[jj]!=bad_BPRN[0]&&BPC.C_PRN[jj]!=bad_BPRN[1]&&BPC.C_PRN[jj]!=bad_BPRN[2]&&BPC.C_PRN[jj]!=bad_BPRN[3]&&BPC.C_PRN[jj]!=bad_BPRN[4])
				if (M2GPRN[ii] == BPC.G_PRN[jj])
				{
					M2_gps_wj[mm2] = M2gps_wj[ii] + BPC.GPC[jj];
					M2_GPS_SR[mm2] = M2GPS_SR[ii];
					M2_GPRN[mm2] = M2GPRN[ii];
					M2_gps_coor.X[mm2] = M2gps_coor.X[ii];
					M2_gps_coor.Y[mm2] = M2gps_coor.Y[ii];
					M2_gps_coor.Z[mm2] = M2gps_coor.Z[ii];
					mm2++;
					break;
				}
			}
		}
		for (int ii = 0; ii<k2; ii++)				//匹配从3个基准站传过来的的通过反距离加权后的BDS伪距改正值;
		{
			for (int jj = 0; jj<pp; jj++)
			{
				//if (M2BPRN[ii]==BPC.C_PRN[jj]&&BPC.C_PRN[jj]!=bad_BPRN[0]&&BPC.C_PRN[jj]!=bad_BPRN[1]&&BPC.C_PRN[jj]!=bad_BPRN[2]&&BPC.C_PRN[jj]!=bad_BPRN[3]&&BPC.C_PRN[jj]!=bad_BPRN[4])
				if (M2BPRN[ii] == BPC.C_PRN[jj])
				{
					M2_bds_wj[kk2] = M2bds_wj[ii] + BPC.CPC[jj];
					M2_BDS_SR[kk2] = M2BDS_SR[ii];
					M2_BPRN[kk2] = M2BPRN[ii];
					M2_bds_coor.X[kk2] = M2bds_coor.X[ii];
					M2_bds_coor.Y[kk2] = M2bds_coor.Y[ii];
					M2_bds_coor.Z[kk2] = M2bds_coor.Z[ii];
					kk2++;
					break;
				}
			}
		}

		/************▼定位解算▼↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
		MM2 = mm2, KK2 = kk2;
		ALL_GB2 = MM2 + KK2;
		if (ALL_GB2 >= 5 && MM2>2 && KK2>2)
		{
			recei_coor(&rcoor2, M2_gps_coor, M2_gps_wj, M2_GPS_SR, M2_bds_coor, M2_bds_wj, M2_BDS_SR, ALL_GB2, MM2, KK2, &GDOP2, &PDOP2, dg[1].tg.second);//计算接收机坐标,返回位置的改正数rcoor.X、rcoor.Y、rcoor.Z;
			if (rcoor2.X != 0 && rcoor2.Y != 0 && rcoor2.Z != 0)
			{
				rcoor2.X = rcoor2.X + M2X0;			//新的接收机坐标=改正数+初值，下面判断，如果delt>0.001的话，返回do，将rcoor.X重新作为初值，循环计算到delt<0.001;
				rcoor2.Y = rcoor2.Y + M2Y0;
				rcoor2.Z = rcoor2.Z + M2Z0;
				//delt = rcoor2.X - M2X0;
				delt = sqrt(pow(rcoor2.X - M2X0,2.0)+pow(rcoor2.Y - M2Y0,2.0)+pow(rcoor2.Z - M2Z0,2.0));

				if (fabs(delt)<0.00001)
					break;
			}
			else
			{
				rcoor2.X = 0;
				rcoor2.Y = 0;
				rcoor2.Z = 0;
				rcoor2.P1 = 0;
				rcoor2.P2 = 0;
				break;
			}
		}
		else
		{
			rcoor2.X = 0;
			rcoor2.Y = 0;
			rcoor2.Z = 0;
			rcoor2.P1 = 0;
			rcoor2.P2 = 0;
			break;
		}
		//if (rcoor2.X!=0&&fabs(delt)<0.00001)
		//	break;
	}while(1);

	rp rcoor_raim=rcoor2;
	int MM_raim=MM2,KK_raim=KK2;
	double GDOP_raim=0.0,PDOP_raim=0.0;
	int chaoxian_num = 0;						//监测站监测卫星，监测有几个超限卫星chaoxian_num;
	int bad_GPRN[20] = { 0 }, bad_BPRN[20] = { 0 };	//存储坏的GPS卫星和坏的BDS卫星;
	int B_bad_num = 0, G_bad_num = 0;								//BDS、GPS残差超限的个数;
	int T = MM_raim + KK_raim;						//多系统定位总的卫星个数Totle;
	int i, j;									//为了进行循环;
	int final_N, final_P;
	double X_raim0, Y_raim0, Z_raim0;
	X_raim0 = rcoor_raim.X;
	Y_raim0 = rcoor_raim.Y;
	Z_raim0 = rcoor_raim.Z;


	double	*ll = new	double[T]();		//课本P57参数  等加以double	(*ll)[1]=	 new	double[T][1];
	double	*mm = new	double[T]();
	double	*nn = new	double[T]();
	double	*L = new	double[T]();
	double	*A = new	double[T * 5]();		//状态矩阵A;
	double	*AT = new	double[5 * T]();		//状态矩阵A的转置;
	double	*P = new	double[T*T]();		//权矩阵P;              ()是对动态内存进行初始化
	double	*ATP = new	double[5 * T]();		//A的转置乘以P;
	double	*ATPA = new	double[5 * 5]();		//A的转置乘以P乘以A;
	double	*inv_ATPA = new	double[5 * 5]();		//(A的转置乘以P乘以A)的逆;
	double	*ATPL = new	double[5]();		//A的转置乘以P乘以L;
	double	*result = new	double[5]();		//(A的转置乘以P乘以A)乘以(A的转置乘以P乘以L)，(inv_ATPA)(ATPL);


	double	*AX = new	double[T]();		//A乘以X;
	double  *V = new	double[T]();		//V=AX-L
	double	*VT = new	double[1 * T]();
	double	*VTP = new	double[1 * T]();
	double	*VTPV = new	double[T * 1]();

	///////////////////////////////////////////列法方程;

	//cout<<"系数矩阵B和L"<<endl;																	//
	for (i = 0; i<MM_raim; i++)
	{
		ll[i] = (M2_gps_coor.X[i] - rcoor_raim.X) / M2_GPS_SR[i];
		mm[i] = (M2_gps_coor.Y[i] - rcoor_raim.Y) / M2_GPS_SR[i];
		nn[i] = (M2_gps_coor.Z[i] - rcoor_raim.Z) / M2_GPS_SR[i];
		A[i * 5 + 0] = ll[i];
		A[i * 5 + 1] = mm[i];
		A[i * 5 + 2] = nn[i];
		A[i * 5 + 3] = -1;
		//A[i*5+4]=0;								//初始化了就不需要了
		L[i] = M2_GPS_SR[i] - M2_gps_wj[i];

		//printf("%8.3f%8.3f%8.3f%8.3f%8.3f%16.3f\n",A[i*5+0],A[i*5+1],A[i*5+2],A[i*5+3],A[i*5+4],L[i]);	//

		P[i*T + i] = 1;									//给GPS定的权
	}
	for (j = MM_raim; j<T; j++)
	{
		ll[j] = (M2_bds_coor.X[j - MM_raim] - rcoor_raim.X) / M2_BDS_SR[j - MM_raim];
		mm[j] = (M2_bds_coor.Y[j - MM_raim] - rcoor_raim.Y) / M2_BDS_SR[j - MM_raim];
		nn[j] = (M2_bds_coor.Z[j - MM_raim] - rcoor_raim.Z) / M2_BDS_SR[j - MM_raim];
		A[j * 5 + 0] = ll[j];
		A[j * 5 + 1] = mm[j];
		A[j * 5 + 2] = nn[j];
		//A[j*5+3]=0;								//初始化了就不需要了;
		A[j * 5 + 4] = -1;
		L[j] = M2_BDS_SR[j - MM_raim] - M2_bds_wj[j - MM_raim];

		//printf("%8.3f%8.3f%8.3f%8.3f%8.3f%16.3f\n",A[j*5+0],A[j*5+1],A[j*5+2],A[j*5+3],A[j*5+4],L[j]);	//

		P[j*T + j] = 1;									//给BDS定的权
	}

	///////////////////////////////////////////通过函数的指针进行矩阵的运算，传出需要的矩阵;
	M_Tra(T, 5, A, AT);							//矩阵转置	A的转置		传出AT;
	M_Mul(5, T, T, AT, P, ATP);						//矩阵相乘	AT乘P		传出ATP;
	M_Mul(5, T, 5, ATP, A, ATPA);					//			ATP乘A		传出ATPA;
	M_Inv(5, ATPA, inv_ATPA);						//矩阵求逆	ATPA的逆		传出inv_ATPA;
	M_Mul(5, T, 1, ATP, L, ATPL);					//			ATP乘L		传出ATPL;
	M_Mul(5, 5, 1, inv_ATPA, ATPL, result);			//			inv_ATPA乘ATPL传出result;

	//cout<<inv_ATPA[1]<<inv_ATPA[2]<<inv_ATPA[3]<<inv_ATPA[4]<<inv_ATPA[5]<<endl;
	//cout<<ATPL[1]<<ATPL[2]<<ATPL[3]<<ATPL[4]<<ATPL[5]<<endl;
	if (inv_ATPA != NULL)
	{
		rcoor_raim.X = result[0];
		rcoor_raim.Y = result[1];
		rcoor_raim.Z = result[2];
		rcoor_raim.P1 = result[3];
		rcoor_raim.P2 = result[4];

		for (i = 0; i<5; i++)
			GDOP_raim += inv_ATPA[i * 5 + i];
		sate_num.GDOP_raim = sqrt(GDOP_raim);
		for (i = 0; i<3; i++)
			PDOP_raim += inv_ATPA[i * 5 + i];
		sate_num.PDOP_raim = sqrt(PDOP_raim);
	}
	else
	{
		rcoor_raim.X = 0;
		rcoor_raim.Y = 0;
		rcoor_raim.Z = 0;
		rcoor_raim.P1 = 0;
		rcoor_raim.P2 = 0;
		//printf("这个历元数据无法求解!\n");
		//system("pause");
	}

	double X[5][1];
	X[0][0] = rcoor_raim.X;
	X[0][1] = rcoor_raim.Y;
	X[0][2] = rcoor_raim.Z;
	X[0][3] = rcoor_raim.P1;
	X[0][4] = rcoor_raim.P2;
	//double	*AX=	new	double[T]();			//A乘以X;
	M_Mul(T, 5, 1, A, X[0], AX);							//矩阵相乘;
	//double  *V=		new	double[T]();			//V=AX-L

	for (int p = 0; p<T; p++)
	{
		V[p] = AX[p] - L[p];
	}
	//double *VT=		new	double[1*T]();
	//double *VTP=	new	double[1*T]();
	//double *VTPV=	new	double[T*1]();

	M_Tra(T, 1, V, VT);								//矩阵转置	A的转置		传出AT;
	M_Mul(1, T, T, VT, P, VTP);							//矩阵相乘	AT乘P		传出ATP;
	M_Mul(1, T, 1, VTP, V, VTPV);
	double RMS_raim = sqrt(*VTPV / (T - 5));
	double w[32];
	for (i = 0; i<T; i++)
	{
		w[i] = fabs(V[i]) / (RMS_raim*sqrt((T - 1.0) / T));
		//printf("%16.8f\n",w[i]);				//
	}
	int n_s=0;
	int NNN,PPP;

	for(i=0;i<T;i++)
	{
		if(w[i]> 3)
		{
			//w1=w[i];
			n_s=i;
			NNN = MM_raim;
			PPP = KK_raim;
			if (n_s>NNN - 1)			//说明是BDS卫星的
			{
				bad_BPRN[chaoxian_num] = M2_BPRN[n_s - NNN];//如果GPS7颗，BDS9颗，现在pp=8，也就是w中第9个，那么就是BDS卫星的第2个对应于1，即8-7=1;
				//chaoxian_num++;
				for(int j=1;j<5;j++)//四个基准站，依次消除坏星
				{
					for (int m=0;m<CBPC[j].C_num;m++)//从0开始依次比对prn
					{
						if (bad_BPRN[chaoxian_num]==CBPC[j].C_PRN[m])//当prn相同时就消除这颗卫星对应的内容
						{
							for (int s = m; s<CBPC[j].C_num; s++)//从坏星开始将后一个星内容覆盖前一个卫星内容
							{
								CBPC[j].C_PRN[s]=CBPC[j].C_PRN[s+1];
								CBPC[j].CPC[s]=CBPC[j].CPC[s+1];
							}
							CBPC[j].C_num--;
							break;
						}
					}
				}
				B_bad_num++;
				KK_raim = PPP - 1;		//新的BDS卫星个数
				chaoxian_num++;
			}
			else					//说明是GPS卫星的
			{
				bad_GPRN[chaoxian_num] = M2_GPRN[n_s];
				for(int j=1;j<5;j++)//四个基准站，依次消除坏星
				{
					for (int m=0;m<CBPC[j].G_num;m++)//从0开始依次比对prn
					{
						if (bad_GPRN[chaoxian_num]==CBPC[j].G_PRN[m])//当prn相同时就消除这颗卫星对应的内容
						{
							for (int s = m; CBPC[j].G_num; s++)//从坏星开始将后一个星内容覆盖前一个卫星内容
							{
								CBPC[j].G_PRN[s]=CBPC[j].G_PRN[s+1];
								CBPC[j].GPC[s]=CBPC[j].GPC[s+1];
							}
							CBPC[j].G_num--;
							break;
						}
					}
				}
				G_bad_num++;
				MM_raim = NNN - 1;		//新的GPS卫星个数
				chaoxian_num++;
			}
		}
	}				
	//MOVING_POS_MODULE4(xyz2ldz6,BBPC, dg0, geph, rcoor2, sate_num,Bn, Bp);
	GRID_MOVING_POS_MODULE(xyz2ldz,m_pos,CBPC, dg0, geph, rcoor2, sate_num, igc);

	if (rcoor2.X != 0 && MM2 != 0 && KK2 != 0)
	{
		sate_num.KK2 = KK2;
		sate_num.MM2 = MM2;
		sate_num.ALL_GB2 = ALL_GB2;
		sate_num.delX2 = rcoor2.X;
		sate_num.delY2 = rcoor2.Y;
		sate_num.delZ2 = rcoor2.Z;
		sate_num.M2_P1 = rcoor2.P1;
		sate_num.M2_P2 = rcoor2.P2;
		sate_num.GDOP2 = GDOP2;
		sate_num.PDOP2 = PDOP2;
	}


}



void CNDGNSS::GRID_MOVING_POS_MODULE1(double  xyz2ldz[],position1 m_pos[],BS_PR_CR CBPC[],DATG dg0[], GEPH geph[MAXPRN_NUM], rp &rcoor2, Sate_NUM &sate_num, int igc)//两点法移动站部分
{
	double	delt = 1;								//do...while()限制条件中的接收机X坐标迭代控制条件
	double	GDOP2 = 0, PDOP2 = 0;
	DATG dg[5] = { 0 };
	int i = 0;
	dg[i + 1] = dg0[0];
	BS_PR_CR BPC;
	int M1gps_num = 0, M1bds_num = 0, M1glo_num = 0;	//<流动站1/2>GPS可见卫星数

	for (int ii = 0; ii<dg[1].nsat; ii++)
	{
		if (dg[1].prn[ii] <= 33)
			M1gps_num++;
		if (dg[1].prn[ii] >= 38 && dg[1].prn[ii] <= 61)
			M1glo_num++;
		if (dg[1].prn[ii] >= 161 && dg[1].prn[ii] <= 197)
			M1bds_num++;
	}


	double	C1X, C1Y, C1Z;							//中心点1坐标
	double	C2X, C2Y, C2Z;							//中心点2坐标
	//double	C3X, C3Y, C3Z;							//中心点3坐标
	//double	C4X, C4Y, C4Z;							//中心点4坐标
	double MX, MY, MZ;                              //流动站坐标
	double C1_M, C2_M;                  //流动站与中心点间距离 C3_M, C4_M
	double s1, s2, s;                   //, s3, s4
	double a1, a2;                      //, a3, a4
	//----------------------------------------------------------------------------------------------------------
	//这里因为是车载，所以流动站一直在变，那么如果流动站有坐标，就用流动站坐标到各基准站的距离，如果流动站坐标为0，就用监测站坐标，一般流动站第一次坐标为0，以后都会有值，为上一次的解得的值;
	IOFH ih3[4] = { 0 };
	//01MNZU
	//02MNYG
	//03ANYE

	for (int i = 0; i<4; i++)
	{
		ih3[i].ntype = 5;
		CString strObs_type = _T("C1 L1 P2 L2 B3");
		memcpy(ih3[i].type, strObs_type, strObs_type.GetLength() + 1);

	}
	int nl=3,nh=3,gc1=10;//3行，3列,第一个网格编号10，下面是对四个网格而言，如有变化还需要改
	if(igc==gc1||igc==gc1+nl+1)
	{
		ih3[0].xyz[0] = m_pos[igc-nl*nh].x;
		ih3[0].xyz[1] = m_pos[igc-nl*nh].y;
		ih3[0].xyz[2] = m_pos[igc-nl*nh].z;
		ih3[1].xyz[0] = m_pos[igc-nl*(nh-1)+1].x;
		ih3[1].xyz[1] = m_pos[igc-nl*(nh-1)+1].y;
		ih3[1].xyz[2] = m_pos[igc-nl*(nh-1)+1].z;
	}
	else if(igc==gc1+1||igc==gc1+nl)
	{
		ih3[0].xyz[0] = m_pos[igc-nl*nh+1].x;
		ih3[0].xyz[1] = m_pos[igc-nl*nh+1].y;
		ih3[0].xyz[2] = m_pos[igc-nl*nh+1].z;
		ih3[1].xyz[0] = m_pos[igc-nl*(nh-1)].x;
		ih3[1].xyz[1] = m_pos[igc-nl*(nh-1)].y;
		ih3[1].xyz[2] = m_pos[igc-nl*(nh-1)].z;
	}
	else
	{
		ih3[0].xyz[0] = 0;
		ih3[0].xyz[1] = 0;
		ih3[0].xyz[2] = 0;
		ih3[1].xyz[0] = 0;
		ih3[1].xyz[1] = 0;
		ih3[1].xyz[2] = 0;
	}


	MX = xyz2ldz[0];
	MY = xyz2ldz[1];
	MZ = xyz2ldz[2];

	C1X = ih3[0].xyz[0];
	C1Y = ih3[0].xyz[1];
	C1Z = ih3[0].xyz[2];
	C2X = ih3[1].xyz[0];
	C2Y = ih3[1].xyz[1];
	C2Z = ih3[1].xyz[2];
	/*C3X = ih3[2].xyz[0];
	C3Y = ih3[2].xyz[1];
	C3Z = ih3[2].xyz[2];
	C4X = ih3[3].xyz[0];
	C4Y = ih3[3].xyz[1];
	C4Z = ih3[3].xyz[2];*/
	if(ih3[0].xyz[0] != 0)
	{
		C1_M = sqrt(pow(C1X - MX, 2) + pow(C1Y - MY, 2) + pow(C1Z - MZ, 2));
		C2_M = sqrt(pow(C2X - MX, 2) + pow(C2Y - MY, 2) + pow(C2Z - MZ, 2));
		/*C3_M = sqrt(pow(C3X - MX, 2) + pow(C3Y - MY, 2) + pow(C3Z - MZ, 2));
		C4_M = sqrt(pow(C4X - MX, 2) + pow(C4Y - MY, 2) + pow(C4Z - MZ, 2));*/

		s1 = 1.0 / C1_M; s2 = 1.0 / C2_M; //s3 = 1.0 / C3_M; s4 = 1.0 / C4_M;
		s = s1 + s2 ;//+ s3 + s4
		a1 = s1 / s; a2 = s2 / s; //a3 = s3 / s; a4 = s4 / s;
	}
	//------------------------------------------------------------------------------------------------------------
	//------------------------------------------------------------------------------------------------------------



	int nn = 0, pp = 0;
	for (int k1 = 0; k1<CBPC[igc-nl*nh].G_num; k1++)						//左上点GPS卫星数igc-nl*nh,NN[]->CBPC[].G_num
	{
		for (int k2 = 0; k2<CBPC[igc-nl*nh+1].G_num; k2++)					//右上点GPS卫星数igc-nl*nh+1
		{
			if (CBPC[igc-nl*nh].G_PRN[k1] == CBPC[igc-nl*nh+1].G_PRN[k2])
			{
				//for (int k3 = 0; k3<CBPC[igc-nl*(nh-1)].G_num; k3++)			//左下点GPS卫星数igc-nl*(nh-1)
				//{
				//	if (CBPC[igc-nl*nh].G_PRN[k1] == CBPC[igc-nl*(nh-1)].G_PRN[k3])
				//	{
				//		for (int k4 = 0; k3<CBPC[igc-nl*(nh-1)+1].G_num; k4++)    //右下点GPS卫星数igc-nl*(nh-1)+1
				//        {
				//			if (CBPC[igc-nl*nh].G_PRN[k1] == CBPC[igc-nl*(nh-1)+1].G_PRN[k4])
				//			{
				BPC.G_PRN[nn] = CBPC[igc-nl*nh].G_PRN[k1];//反距离加权后的BPC除伪距改正项外，其他与主控站一致;
				BPC.GPC[nn] = a1*CBPC[igc-nl*nh].GPC[k1] + a2*CBPC[igc-nl*nh+1].GPC[k2];// + a3*CBPC[igc-nl*(nh-1)].GPC[k3] + a4*CBPC[igc-nl*(nh-1)+1].GPC[k4]
				nn++;
				break;
				/*			}
				}
				break;
				}
				}
				break;*/
			}
		}
	}
	for (int k1 = 0; k1<CBPC[igc-nl*nh].C_num; k1++)						//左上BDS卫星数igc-nl*nh
	{
		for (int k2 = 0; k2<CBPC[igc-nl*nh+1].C_num; k2++)					//右上点3BDS卫星数igc-nl*nh+1
		{
			if (CBPC[igc-nl*nh].C_PRN[k1] == CBPC[igc-nl*nh+1].C_PRN[k2])
			{
				//for (int k3 = 0; k3<CBPC[igc-nl*(nh-1)].C_num; k3++)			//左下点7BDS卫星数igc-nl*(nh-1)
				//{
				//	if (CBPC[igc-nl*nh].C_PRN[k1] == CBPC[igc-nl*(nh-1)].C_PRN[k3])
				//	{
				//		for (int k4 = 0; k3<CBPC[igc-nl*(nh-1)+1].C_num; k4++)    //右下点8BDS卫星数igc-nl*(nh-1)+1
				//        {
				//			if (CBPC[igc-nl*nh].C_PRN[k1] == CBPC[igc-nl*(nh-1)+1].C_PRN[k4])
				//			{
				BPC.C_PRN[pp] = CBPC[igc-nl*nh].C_PRN[k1];
				BPC.CPC[pp] = a1*CBPC[igc-nl*nh].CPC[k1] + a2*CBPC[igc-nl*nh+1].CPC[k2];// + a3*CBPC[igc-nl*(nh-1)].CPC[k3] + a4*CBPC[igc-nl*(nh-1)+1].CPC[k4]
				pp++;
				break;
				/*	}
				}
				break;
				}
				}
				break;*/
			}
		}
	}




	/************▼流动站1  dg[1]计算▼↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/

	double	M2X0, M2Y0, M2Z0;							//流动站初始坐标;
	double	M2g_swj, M2g_R, M2b_swj, M2b_R;
	double	M2G_XK, M2G_YK, M2G_ZK, M2B_XK, M2B_YK, M2B_ZK;	//初始坐标;
	int		MM2, KK2, ALL_GB2;
	//rp		rcoor2={0};
	rcoor2.X = xyz2ldz[0];
	rcoor2.Y = xyz2ldz[1];
	rcoor2.Z = xyz2ldz[2];



	for (int xunhuan = 0; xunhuan<15; xunhuan++)			//最多循环10次跳出，代替do。。。。while
	{
		double	M2gps_wj[32] = { 0 }, M2GPS_SR[32] = { 0 };	//流动站解算的gps伪距&近似距离——存储值;
		double	M2bds_wj[35] = { 0 }, M2BDS_SR[35] = { 0 };	//流动站解算的bds伪距&近似距离——存储值;
		int		M2GPRN[32] = { 0 };						//流动站gpsPRN号——存储值;
		int		M2BPRN[35] = { 0 };						//流动站bdsPRN号——存储值;
		sp		M2gps_coor = { 0 }, M2bds_coor = { 0 };		//流动站解算的gps与bds的卫星坐标——存储值;

		double	M2_gps_wj[32] = { 0 }, M2_GPS_SR[32] = { 0 };//流动站最终解算;
		double	M2_bds_wj[35] = { 0 }, M2_BDS_SR[35] = { 0 };//流动站最终解算;
		int		M2_GPRN[32] = { 0 };					//流动站最终解算;
		int		M2_BPRN[35] = { 0 };					//流动站最终解算;
		sp		M2_gps_coor = { 0 }, M2_bds_coor = { 0 };	//流动站最终解算;


		double check2_gps[32] = { 0 }, check2_bds[35] = { 0 };//检测伪距改正输出;
		int	m2 = 0, k2 = 0;								//循环回代置零;
		M2X0 = rcoor2.X;								//用于循环回代;
		M2Y0 = rcoor2.Y;
		M2Z0 = rcoor2.Z;

		for (int ii = 0; ii<M1gps_num; ii++)				//基于流动站计算卫星位置及伪距&卫地距;
		{
			M2g_swj = 0, M2g_R = 0;
			M2G_XK = 0, M2G_YK = 0, M2G_ZK = 0;
			GNSS_POS_MODULE(geph, dg, 1, M2X0, M2Y0, M2Z0, &M2g_swj, &M2g_R, &M2G_XK, &M2G_YK, &M2G_ZK, ii, 1);//dg后面的参数为站号,为了配合dg【】中的号;
			if (M2g_swj != 0 && M2g_R != 0)
			{
				M2gps_wj[m2] = M2g_swj;
				M2GPS_SR[m2] = M2g_R;
				M2GPRN[m2] = dg[1].prn[ii];
				M2gps_coor.X[m2] = M2G_XK;
				M2gps_coor.Y[m2] = M2G_YK;
				M2gps_coor.Z[m2] = M2G_ZK;

				check2_gps[m2] = M2g_R - M2g_swj;					//检测改正值正确与否,与BDS的改正值对比,注意：检测时要加入卫星钟差，以使对比与BDS的改正值是否一致,正确的应该和BDS是一致的;
				m2++;											//m为可利用GPS卫星数目
			}
		}
		for (int ii = M1gps_num + M1glo_num; ii<dg[1].nsat; ii++)		//基于流动站计算卫星位置及伪距&卫地距;
		{
			M2b_swj = 0, M2b_R = 0;
			M2B_XK = 0, M2B_YK = 0, M2B_ZK = 0;
			GNSS_POS_MODULE(geph, dg, 1, M2X0, M2Y0, M2Z0, &M2b_swj, &M2b_R, &M2B_XK, &M2B_YK, &M2B_ZK, ii, 2);//dg后面的参数为站号,为了配合dg【】中的号;
			if (M2b_swj != 0 && M2b_R != 0)
			{
				M2bds_wj[k2] = M2b_swj;
				M2BDS_SR[k2] = M2b_R;
				M2BPRN[k2] = dg[1].prn[ii];
				M2bds_coor.X[k2] = M2B_XK;
				M2bds_coor.Y[k2] = M2B_YK;
				M2bds_coor.Z[k2] = M2B_ZK;

				check2_bds[k2] = M2b_R - M2b_swj;			//检测改正值正确与否,与GPS的改正值对比,注意：检测时要加入卫星钟差，以使对比与GPS的改正值是否一致,正确的应该和GPS是一致的;
				k2++;								//m为可利用GPS卫星数目
			}
		}

		/********▼匹配伪距改正数▼********/;
		int mm2 = 0, kk2 = 0;							//该历元中流动站和改正数相匹配的数;
		for (int ii = 0; ii<m2; ii++)				//匹配从3个基准站传过来的通过反距离加权后的GPS伪距改正值;
		{
			for (int jj = 0; jj<nn; jj++)
			{
				//if (M2GPRN[ii]==BPC.G_PRN[jj]&&BPC.C_PRN[jj]!=bad_BPRN[0]&&BPC.C_PRN[jj]!=bad_BPRN[1]&&BPC.C_PRN[jj]!=bad_BPRN[2]&&BPC.C_PRN[jj]!=bad_BPRN[3]&&BPC.C_PRN[jj]!=bad_BPRN[4])
				if (M2GPRN[ii] == BPC.G_PRN[jj])
				{
					M2_gps_wj[mm2] = M2gps_wj[ii] + BPC.GPC[jj];
					M2_GPS_SR[mm2] = M2GPS_SR[ii];
					M2_GPRN[mm2] = M2GPRN[ii];
					M2_gps_coor.X[mm2] = M2gps_coor.X[ii];
					M2_gps_coor.Y[mm2] = M2gps_coor.Y[ii];
					M2_gps_coor.Z[mm2] = M2gps_coor.Z[ii];
					mm2++;
					break;
				}
			}
		}
		for (int ii = 0; ii<k2; ii++)				//匹配从3个基准站传过来的的通过反距离加权后的BDS伪距改正值;
		{
			for (int jj = 0; jj<pp; jj++)
			{
				//if (M2BPRN[ii]==BPC.C_PRN[jj]&&BPC.C_PRN[jj]!=bad_BPRN[0]&&BPC.C_PRN[jj]!=bad_BPRN[1]&&BPC.C_PRN[jj]!=bad_BPRN[2]&&BPC.C_PRN[jj]!=bad_BPRN[3]&&BPC.C_PRN[jj]!=bad_BPRN[4])
				if (M2BPRN[ii] == BPC.C_PRN[jj])
				{
					M2_bds_wj[kk2] = M2bds_wj[ii] + BPC.CPC[jj];
					M2_BDS_SR[kk2] = M2BDS_SR[ii];
					M2_BPRN[kk2] = M2BPRN[ii];
					M2_bds_coor.X[kk2] = M2bds_coor.X[ii];
					M2_bds_coor.Y[kk2] = M2bds_coor.Y[ii];
					M2_bds_coor.Z[kk2] = M2bds_coor.Z[ii];
					kk2++;
					break;
				}
			}
		}

		/************▼定位解算▼↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
		MM2 = mm2, KK2 = kk2;
		ALL_GB2 = MM2 + KK2;
		if (ALL_GB2 >= 5 && MM2>2 && KK2>2)
		{
			recei_coor(&rcoor2, M2_gps_coor, M2_gps_wj, M2_GPS_SR, M2_bds_coor, M2_bds_wj, M2_BDS_SR, ALL_GB2, MM2, KK2, &GDOP2, &PDOP2, dg[1].tg.second);//计算接收机坐标,返回位置的改正数rcoor.X、rcoor.Y、rcoor.Z;
			if (rcoor2.X != 0 && rcoor2.Y != 0 && rcoor2.Z != 0)
			{
				rcoor2.X = rcoor2.X + M2X0;			//新的接收机坐标=改正数+初值，下面判断，如果delt>0.001的话，返回do，将rcoor.X重新作为初值，循环计算到delt<0.001;
				rcoor2.Y = rcoor2.Y + M2Y0;
				rcoor2.Z = rcoor2.Z + M2Z0;
				//delt = rcoor2.X - M2X0;
				delt = sqrt(pow(rcoor2.X - M2X0,2.0)+pow(rcoor2.Y - M2Y0,2.0)+pow(rcoor2.Z - M2Z0,2.0));

				if (fabs(delt)<0.00001)
					break;
			}
			else
			{
				rcoor2.X = 0;
				rcoor2.Y = 0;
				rcoor2.Z = 0;
				rcoor2.P1 = 0;
				rcoor2.P2 = 0;
				break;
			}
		}
		else
		{
			rcoor2.X = 0;
			rcoor2.Y = 0;
			rcoor2.Z = 0;
			rcoor2.P1 = 0;
			rcoor2.P2 = 0;
			break;
		}
		//if (rcoor2.X!=0&&fabs(delt)<0.00001)
		//	break;
	}

	if (rcoor2.X != 0 && MM2 != 0 && KK2 != 0)
	{
		sate_num.KK2 = KK2;
		sate_num.MM2 = MM2;
		sate_num.ALL_GB2 = ALL_GB2;
		sate_num.delX2 = rcoor2.X;
		sate_num.delY2 = rcoor2.Y;
		sate_num.delZ2 = rcoor2.Z;
		sate_num.M2_P1 = rcoor2.P1;
		sate_num.M2_P2 = rcoor2.P2;
		sate_num.GDOP2 = GDOP2;
		sate_num.PDOP2 = PDOP2;
	}


}


void CNDGNSS::GRID_MOVING_POS_MODULE2(double  xyz2ldz[],position1 m_pos[],BS_PR_CR CBPC[],DATG dg0[], GEPH geph[MAXPRN_NUM], rp &rcoor2, Sate_NUM &sate_num, int igc)//1*1度网格四点法伪距差分移动站
{
	double	delt = 1;								//do...while()限制条件中的接收机X坐标迭代控制条件
	double	GDOP2 = 0, PDOP2 = 0;
	DATG dg[5] = { 0 };
	int i = 0;
	dg[i + 1] = dg0[0];
	BS_PR_CR BPC;
	int M1gps_num = 0, M1bds_num = 0, M1glo_num = 0;	//<流动站1/2>GPS可见卫星数

	for (int ii = 0; ii<dg[1].nsat; ii++)
	{
		if (dg[1].prn[ii] <= 33)
			M1gps_num++;
		if (dg[1].prn[ii] >= 38 && dg[1].prn[ii] <= 61)
			M1glo_num++;
		if (dg[1].prn[ii] >= 161 && dg[1].prn[ii] <= 197)
			M1bds_num++;
	}


	double	C1X, C1Y, C1Z;							//网格点1坐标
	double	C2X, C2Y, C2Z;							//网格点2坐标
	double	C3X, C3Y, C3Z;							//网格点3坐标
	double	C4X, C4Y, C4Z;							//网格点4坐标
	double MX, MY, MZ;                              //流动站坐标
	double C1_M, C2_M, C3_M, C4_M;                  //流动站与中心点间距离
	double s1, s2, s3, s4, s;
	double a1, a2, a3, a4;
	//----------------------------------------------------------------------------------------------------------
	//这里因为是车载，所以流动站一直在变，那么如果流动站有坐标，就用流动站坐标到各基准站的距离，如果流动站坐标为0，就用监测站坐标，一般流动站第一次坐标为0，以后都会有值，为上一次的解得的值;
	IOFH ih3[4] = { 0 };
	//01MNZU
	//02MNYG
	//03ANYE

	for (int i = 0; i<4; i++)
	{
		ih3[i].ntype = 5;
		CString strObs_type = _T("C1 L1 P2 L2 B3");
		memcpy(ih3[i].type, strObs_type, strObs_type.GetLength() + 1);

	}
	int nl=3,nh=3;//3行，3列
	ih3[0].xyz[0] = m_pos[igc-nl*nh].x;//1号网格点10-9
	ih3[0].xyz[1] = m_pos[igc-nl*nh].y;
	ih3[0].xyz[2] = m_pos[igc-nl*nh].z;
	ih3[1].xyz[0] = m_pos[igc-nl*nh+2].x;//3号网格点10-9+2
	ih3[1].xyz[1] = m_pos[igc-nl*nh+2].y;
	ih3[1].xyz[2] = m_pos[igc-nl*nh+2].z;
	ih3[2].xyz[0] = m_pos[igc-nl*(nh-2)].x;//7号网格点10-3
	ih3[2].xyz[1] = m_pos[igc-nl*(nh-2)].y;
	ih3[2].xyz[2] = m_pos[igc-nl*(nh-2)].z;
	ih3[3].xyz[0] = m_pos[igc-nl*(nh-2)+2].x;//9号网格点10-3+2
	ih3[3].xyz[1] = m_pos[igc-nl*(nh-2)+2].y;
	ih3[3].xyz[2] = m_pos[igc-nl*(nh-2)+2].z;


	MX = xyz2ldz[0];
	MY = xyz2ldz[1];
	MZ = xyz2ldz[2];

	C1X = ih3[0].xyz[0];
	C1Y = ih3[0].xyz[1];
	C1Z = ih3[0].xyz[2];
	C2X = ih3[1].xyz[0];
	C2Y = ih3[1].xyz[1];
	C2Z = ih3[1].xyz[2];
	C3X = ih3[2].xyz[0];
	C3Y = ih3[2].xyz[1];
	C3Z = ih3[2].xyz[2];
	C4X = ih3[3].xyz[0];
	C4Y = ih3[3].xyz[1];
	C4Z = ih3[3].xyz[2];

	C1_M = sqrt(pow(C1X - MX, 2) + pow(C1Y - MY, 2) + pow(C1Z - MZ, 2));
	C2_M = sqrt(pow(C2X - MX, 2) + pow(C2Y - MY, 2) + pow(C2Z - MZ, 2));
	C3_M = sqrt(pow(C3X - MX, 2) + pow(C3Y - MY, 2) + pow(C3Z - MZ, 2));
	C4_M = sqrt(pow(C4X - MX, 2) + pow(C4Y - MY, 2) + pow(C4Z - MZ, 2));

	s1 = 1.0 / C1_M; s2 = 1.0 / C2_M; s3 = 1.0 / C3_M; s4 = 1.0 / C4_M;
	s = s1 + s2 + s3 + s4;
	a1 = s1 / s; a2 = s2 / s; a3 = s3 / s; a4 = s4 / s;
	//------------------------------------------------------------------------------------------------------------
	//------------------------------------------------------------------------------------------------------------



	int nn = 0, pp = 0;
	for (int k1 = 0; k1<CBPC[igc-nl*nh].G_num; k1++)						//左上点GPS卫星数igc-nl*nh,NN[]->CBPC[].G_num
	{
		for (int k2 = 0; k2<CBPC[igc-nl*nh+2].G_num; k2++)					//右上点GPS卫星数igc-nl*nh+1
		{
			if (CBPC[igc-nl*nh].G_PRN[k1] == CBPC[igc-nl*nh+2].G_PRN[k2])
			{
				for (int k3 = 0; k3<CBPC[igc-nl*(nh-2)].G_num; k3++)			//左下点GPS卫星数igc-nl*(nh-1)
				{
					if (CBPC[igc-nl*nh].G_PRN[k1] == CBPC[igc-nl*(nh-2)].G_PRN[k3])
					{
						for (int k4 = 0; k3<CBPC[igc-nl*(nh-2)+2].G_num; k4++)    //右下点GPS卫星数igc-nl*(nh-1)+1
						{
							if (CBPC[igc-nl*nh].G_PRN[k1] == CBPC[igc-nl*(nh-2)+2].G_PRN[k4])
							{
								BPC.G_PRN[nn] = CBPC[igc-nl*nh].G_PRN[k1];//反距离加权后的BPC除伪距改正项外，其他与主控站一致;
								BPC.GPC[nn] = a1*CBPC[igc-nl*nh].GPC[k1] + a2*CBPC[igc-nl*nh+2].GPC[k2] + a3*CBPC[igc-nl*(nh-2)].GPC[k3] + a4*CBPC[igc-nl*(nh-2)+2].GPC[k4];
								nn++;
								break;
							}
						}
						break;
					}
				}
				break;
			}
		}
	}
	for (int k1 = 0; k1<CBPC[igc-nl*nh].C_num; k1++)						//左上BDS卫星数igc-nl*nh
	{
		for (int k2 = 0; k2<CBPC[igc-nl*nh+2].C_num; k2++)					//右上点3BDS卫星数igc-nl*nh+1
		{
			if (CBPC[igc-nl*nh].C_PRN[k1] == CBPC[igc-nl*nh+2].C_PRN[k2])
			{
				for (int k3 = 0; k3<CBPC[igc-nl*(nh-2)].C_num; k3++)			//左下点7BDS卫星数igc-nl*(nh-1)
				{
					if (CBPC[igc-nl*nh].C_PRN[k1] == CBPC[igc-nl*(nh-2)].C_PRN[k3])
					{
						for (int k4 = 0; k3<CBPC[igc-nl*(nh-2)+2].C_num; k4++)    //右下点8BDS卫星数igc-nl*(nh-1)+1
						{
							if (CBPC[igc-nl*nh].C_PRN[k1] == CBPC[igc-nl*(nh-2)+2].C_PRN[k4])
							{
								BPC.C_PRN[pp] = CBPC[igc-nl*nh].C_PRN[k1];
								BPC.CPC[pp] = a1*CBPC[igc-nl*nh].CPC[k1] + a2*CBPC[igc-nl*nh+2].CPC[k2] + a3*CBPC[igc-nl*(nh-2)].CPC[k3] + a4*CBPC[igc-nl*(nh-2)+2].CPC[k4];
								pp++;
								break;
							}
						}
						break;
					}
				}
				break;
			}
		}
	}




	/************▼流动站1  dg[1]计算▼↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/

	double	M2X0, M2Y0, M2Z0;							//流动站初始坐标;
	double	M2g_swj, M2g_R, M2b_swj, M2b_R;
	double	M2G_XK, M2G_YK, M2G_ZK, M2B_XK, M2B_YK, M2B_ZK;	//初始坐标;
	int		MM2, KK2, ALL_GB2;
	//rp		rcoor2={0};
	rcoor2.X = xyz2ldz[0];
	rcoor2.Y = xyz2ldz[1];
	rcoor2.Z = xyz2ldz[2];



	for (int xunhuan = 0; xunhuan<15; xunhuan++)			//最多循环10次跳出，代替do。。。。while
	{
		double	M2gps_wj[32] = { 0 }, M2GPS_SR[32] = { 0 };	//流动站解算的gps伪距&近似距离——存储值;
		double	M2bds_wj[35] = { 0 }, M2BDS_SR[35] = { 0 };	//流动站解算的bds伪距&近似距离——存储值;
		int		M2GPRN[32] = { 0 };						//流动站gpsPRN号——存储值;
		int		M2BPRN[35] = { 0 };						//流动站bdsPRN号——存储值;
		sp		M2gps_coor = { 0 }, M2bds_coor = { 0 };		//流动站解算的gps与bds的卫星坐标——存储值;

		double	M2_gps_wj[32] = { 0 }, M2_GPS_SR[32] = { 0 };//流动站最终解算;
		double	M2_bds_wj[35] = { 0 }, M2_BDS_SR[35] = { 0 };//流动站最终解算;
		int		M2_GPRN[32] = { 0 };					//流动站最终解算;
		int		M2_BPRN[35] = { 0 };					//流动站最终解算;
		sp		M2_gps_coor = { 0 }, M2_bds_coor = { 0 };	//流动站最终解算;


		double check2_gps[32] = { 0 }, check2_bds[35] = { 0 };//检测伪距改正输出;
		int	m2 = 0, k2 = 0;								//循环回代置零;
		M2X0 = rcoor2.X;								//用于循环回代;
		M2Y0 = rcoor2.Y;
		M2Z0 = rcoor2.Z;

		for (int ii = 0; ii<M1gps_num; ii++)				//基于流动站计算卫星位置及伪距&卫地距;
		{
			M2g_swj = 0, M2g_R = 0;
			M2G_XK = 0, M2G_YK = 0, M2G_ZK = 0;
			GNSS_POS_MODULE(geph, dg, 1, M2X0, M2Y0, M2Z0, &M2g_swj, &M2g_R, &M2G_XK, &M2G_YK, &M2G_ZK, ii, 1);//dg后面的参数为站号,为了配合dg【】中的号;
			if (M2g_swj != 0 && M2g_R != 0)
			{
				M2gps_wj[m2] = M2g_swj;
				M2GPS_SR[m2] = M2g_R;
				M2GPRN[m2] = dg[1].prn[ii];
				M2gps_coor.X[m2] = M2G_XK;
				M2gps_coor.Y[m2] = M2G_YK;
				M2gps_coor.Z[m2] = M2G_ZK;

				check2_gps[m2] = M2g_R - M2g_swj;					//检测改正值正确与否,与BDS的改正值对比,注意：检测时要加入卫星钟差，以使对比与BDS的改正值是否一致,正确的应该和BDS是一致的;
				m2++;											//m为可利用GPS卫星数目
			}
		}
		for (int ii = M1gps_num + M1glo_num; ii<dg[1].nsat; ii++)		//基于流动站计算卫星位置及伪距&卫地距;
		{
			M2b_swj = 0, M2b_R = 0;
			M2B_XK = 0, M2B_YK = 0, M2B_ZK = 0;
			GNSS_POS_MODULE(geph, dg, 1, M2X0, M2Y0, M2Z0, &M2b_swj, &M2b_R, &M2B_XK, &M2B_YK, &M2B_ZK, ii, 2);//dg后面的参数为站号,为了配合dg【】中的号;
			if (M2b_swj != 0 && M2b_R != 0)
			{
				M2bds_wj[k2] = M2b_swj;
				M2BDS_SR[k2] = M2b_R;
				M2BPRN[k2] = dg[1].prn[ii];
				M2bds_coor.X[k2] = M2B_XK;
				M2bds_coor.Y[k2] = M2B_YK;
				M2bds_coor.Z[k2] = M2B_ZK;

				check2_bds[k2] = M2b_R - M2b_swj;			//检测改正值正确与否,与GPS的改正值对比,注意：检测时要加入卫星钟差，以使对比与GPS的改正值是否一致,正确的应该和GPS是一致的;
				k2++;								//m为可利用GPS卫星数目
			}
		}

		/********▼匹配伪距改正数▼********/;
		int mm2 = 0, kk2 = 0;							//该历元中流动站和改正数相匹配的数;
		for (int ii = 0; ii<m2; ii++)				//匹配从3个基准站传过来的通过反距离加权后的GPS伪距改正值;
		{
			for (int jj = 0; jj<nn; jj++)
			{
				//if (M2GPRN[ii]==BPC.G_PRN[jj]&&BPC.C_PRN[jj]!=bad_BPRN[0]&&BPC.C_PRN[jj]!=bad_BPRN[1]&&BPC.C_PRN[jj]!=bad_BPRN[2]&&BPC.C_PRN[jj]!=bad_BPRN[3]&&BPC.C_PRN[jj]!=bad_BPRN[4])
				if (M2GPRN[ii] == BPC.G_PRN[jj])
				{
					M2_gps_wj[mm2] = M2gps_wj[ii] + BPC.GPC[jj];
					M2_GPS_SR[mm2] = M2GPS_SR[ii];
					M2_GPRN[mm2] = M2GPRN[ii];
					M2_gps_coor.X[mm2] = M2gps_coor.X[ii];
					M2_gps_coor.Y[mm2] = M2gps_coor.Y[ii];
					M2_gps_coor.Z[mm2] = M2gps_coor.Z[ii];
					mm2++;
					break;
				}
			}
		}
		for (int ii = 0; ii<k2; ii++)				//匹配从3个基准站传过来的的通过反距离加权后的BDS伪距改正值;
		{
			for (int jj = 0; jj<pp; jj++)
			{
				//if (M2BPRN[ii]==BPC.C_PRN[jj]&&BPC.C_PRN[jj]!=bad_BPRN[0]&&BPC.C_PRN[jj]!=bad_BPRN[1]&&BPC.C_PRN[jj]!=bad_BPRN[2]&&BPC.C_PRN[jj]!=bad_BPRN[3]&&BPC.C_PRN[jj]!=bad_BPRN[4])
				if (M2BPRN[ii] == BPC.C_PRN[jj])
				{
					M2_bds_wj[kk2] = M2bds_wj[ii] + BPC.CPC[jj];
					M2_BDS_SR[kk2] = M2BDS_SR[ii];
					M2_BPRN[kk2] = M2BPRN[ii];
					M2_bds_coor.X[kk2] = M2bds_coor.X[ii];
					M2_bds_coor.Y[kk2] = M2bds_coor.Y[ii];
					M2_bds_coor.Z[kk2] = M2bds_coor.Z[ii];
					kk2++;
					break;
				}
			}
		}

		/************▼定位解算▼↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
		MM2 = mm2, KK2 = kk2;
		ALL_GB2 = MM2 + KK2;
		if (ALL_GB2 >= 5 && MM2>2 && KK2>2)
		{
			recei_coor(&rcoor2, M2_gps_coor, M2_gps_wj, M2_GPS_SR, M2_bds_coor, M2_bds_wj, M2_BDS_SR, ALL_GB2, MM2, KK2, &GDOP2, &PDOP2, dg[1].tg.second);//计算接收机坐标,返回位置的改正数rcoor.X、rcoor.Y、rcoor.Z;
			if (rcoor2.X != 0 && rcoor2.Y != 0 && rcoor2.Z != 0)
			{
				rcoor2.X = rcoor2.X + M2X0;			//新的接收机坐标=改正数+初值，下面判断，如果delt>0.001的话，返回do，将rcoor.X重新作为初值，循环计算到delt<0.001;
				rcoor2.Y = rcoor2.Y + M2Y0;
				rcoor2.Z = rcoor2.Z + M2Z0;
				//delt = rcoor2.X - M2X0;
				delt = sqrt(pow(rcoor2.X - M2X0,2.0)+pow(rcoor2.Y - M2Y0,2.0)+pow(rcoor2.Z - M2Z0,2.0));

				if (fabs(delt)<0.00001)
					break;
			}
			else
			{
				rcoor2.X = 0;
				rcoor2.Y = 0;
				rcoor2.Z = 0;
				rcoor2.P1 = 0;
				rcoor2.P2 = 0;
				break;
			}
		}
		else
		{
			rcoor2.X = 0;
			rcoor2.Y = 0;
			rcoor2.Z = 0;
			rcoor2.P1 = 0;
			rcoor2.P2 = 0;
			break;
		}
		//if (rcoor2.X!=0&&fabs(delt)<0.00001)
		//	break;
	}

	if (rcoor2.X != 0 && MM2 != 0 && KK2 != 0)
	{
		sate_num.KK2 = KK2;
		sate_num.MM2 = MM2;
		sate_num.ALL_GB2 = ALL_GB2;
		sate_num.delX2 = rcoor2.X;
		sate_num.delY2 = rcoor2.Y;
		sate_num.delZ2 = rcoor2.Z;
		sate_num.M2_P1 = rcoor2.P1;
		sate_num.M2_P2 = rcoor2.P2;
		sate_num.GDOP2 = GDOP2;
		sate_num.PDOP2 = PDOP2;
	}


}



void CNDGNSS::GRID_MOVING_POS_MODULE3(double  xyz2ldz[],position1 m_pos[],BS_PR_CR CBPC[],DATG dg0[], GEPH geph[MAXPRN_NUM], rp &rcoor2, Sate_NUM &sate_num, int igc)//2*2度网格四点法伪距差分移动站
{
	double	delt = 1;								//do...while()限制条件中的接收机X坐标迭代控制条件
	double	GDOP2 = 0, PDOP2 = 0;
	DATG dg[5] = { 0 };
	int i = 0;
	dg[i + 1] = dg0[0];
	BS_PR_CR BPC;
	int M1gps_num = 0, M1bds_num = 0, M1glo_num = 0;	//<流动站1/2>GPS可见卫星数

	for (int ii = 0; ii<dg[1].nsat; ii++)
	{
		if (dg[1].prn[ii] <= 33)
			M1gps_num++;
		if (dg[1].prn[ii] >= 38 && dg[1].prn[ii] <= 61)
			M1glo_num++;
		if (dg[1].prn[ii] >= 161 && dg[1].prn[ii] <= 197)
			M1bds_num++;
	}


	double	C1X, C1Y, C1Z;							//网格点1坐标
	double	C2X, C2Y, C2Z;							//网格点2坐标
	double	C3X, C3Y, C3Z;							//网格点3坐标
	double	C4X, C4Y, C4Z;							//网格点4坐标
	double MX, MY, MZ;                              //流动站坐标
	double C1_M, C2_M, C3_M, C4_M;                  //流动站与中心点间距离
	double s1, s2, s3, s4, s;
	double a1, a2, a3, a4;
	//----------------------------------------------------------------------------------------------------------
	//这里因为是车载，所以流动站一直在变，那么如果流动站有坐标，就用流动站坐标到各基准站的距离，如果流动站坐标为0，就用监测站坐标，一般流动站第一次坐标为0，以后都会有值，为上一次的解得的值;
	IOFH ih3[4] = { 0 };
	//01MNZU
	//02MNYG
	//03ANYE

	for (int i = 0; i<4; i++)
	{
		ih3[i].ntype = 5;
		CString strObs_type = _T("C1 L1 P2 L2 B3");
		memcpy(ih3[i].type, strObs_type, strObs_type.GetLength() + 1);

	}
	int igcc1=15,igcc2=16,igcc3=17,igcc4=18;//每次都改用那些就写上那些网格点
	ih3[0].xyz[0] = m_pos[igcc1].x;
	ih3[0].xyz[1] = m_pos[igcc1].y;
	ih3[0].xyz[2] = m_pos[igcc1].z;
	ih3[1].xyz[0] = m_pos[igcc2].x;
	ih3[1].xyz[1] = m_pos[igcc2].y;
	ih3[1].xyz[2] = m_pos[igcc2].z;
	ih3[2].xyz[0] = m_pos[igcc3].x;
	ih3[2].xyz[1] = m_pos[igcc3].y;
	ih3[2].xyz[2] = m_pos[igcc3].z;
	ih3[3].xyz[0] = m_pos[igcc4].x;
	ih3[3].xyz[1] = m_pos[igcc4].y;
	ih3[3].xyz[2] = m_pos[igcc4].z;


	MX = xyz2ldz[0];
	MY = xyz2ldz[1];
	MZ = xyz2ldz[2];

	C1X = ih3[0].xyz[0];
	C1Y = ih3[0].xyz[1];
	C1Z = ih3[0].xyz[2];
	C2X = ih3[1].xyz[0];
	C2Y = ih3[1].xyz[1];
	C2Z = ih3[1].xyz[2];
	C3X = ih3[2].xyz[0];
	C3Y = ih3[2].xyz[1];
	C3Z = ih3[2].xyz[2];
	C4X = ih3[3].xyz[0];
	C4Y = ih3[3].xyz[1];
	C4Z = ih3[3].xyz[2];

	C1_M = sqrt(pow(C1X - MX, 2) + pow(C1Y - MY, 2) + pow(C1Z - MZ, 2));
	C2_M = sqrt(pow(C2X - MX, 2) + pow(C2Y - MY, 2) + pow(C2Z - MZ, 2));
	C3_M = sqrt(pow(C3X - MX, 2) + pow(C3Y - MY, 2) + pow(C3Z - MZ, 2));
	C4_M = sqrt(pow(C4X - MX, 2) + pow(C4Y - MY, 2) + pow(C4Z - MZ, 2));

	s1 = 1.0 / C1_M; s2 = 1.0 / C2_M; s3 = 1.0 / C3_M; s4 = 1.0 / C4_M;
	s = s1 + s2 + s3 + s4;
	a1 = s1 / s; a2 = s2 / s; a3 = s3 / s; a4 = s4 / s;
	//------------------------------------------------------------------------------------------------------------
	//------------------------------------------------------------------------------------------------------------



	int nn = 0, pp = 0;
	for (int k1 = 0; k1<CBPC[igcc1].G_num; k1++)						//左上点GPS卫星数igc-nl*nh,NN[]->CBPC[].G_num
	{
		for (int k2 = 0; k2<CBPC[igcc2].G_num; k2++)					//右上点GPS卫星数igc-nl*nh+1
		{
			if (CBPC[igcc1].G_PRN[k1] == CBPC[igcc2].G_PRN[k2])
			{
				for (int k3 = 0; k3<CBPC[igcc3].G_num; k3++)			//左下点GPS卫星数igc-nl*(nh-1)
				{
					if (CBPC[igcc1].G_PRN[k1] == CBPC[igcc3].G_PRN[k3])
					{
						for (int k4 = 0; k3<CBPC[igcc4].G_num; k4++)    //右下点GPS卫星数igc-nl*(nh-1)+1
						{
							if (CBPC[igcc1].G_PRN[k1] == CBPC[igcc4].G_PRN[k4])
							{
								BPC.G_PRN[nn] = CBPC[igcc1].G_PRN[k1];//反距离加权后的BPC除伪距改正项外，其他与主控站一致;
								BPC.GPC[nn] = a1*CBPC[igcc1].GPC[k1] + a2*CBPC[igcc2].GPC[k2] + a3*CBPC[igcc3].GPC[k3] + a4*CBPC[igcc4].GPC[k4];
								nn++;
								break;
							}
						}
						break;
					}
				}
				break;
			}
		}
	}
	for (int k1 = 0; k1<CBPC[igcc1].C_num; k1++)						//左上BDS卫星数igc-nl*nh
	{
		for (int k2 = 0; k2<CBPC[igcc2].C_num; k2++)					//右上点3BDS卫星数igc-nl*nh+1
		{
			if (CBPC[igcc1].C_PRN[k1] == CBPC[igcc2].C_PRN[k2])
			{
				for (int k3 = 0; k3<CBPC[igcc3].C_num; k3++)			//左下点7BDS卫星数igc-nl*(nh-1)
				{
					if (CBPC[igcc1].C_PRN[k1] == CBPC[igcc3].C_PRN[k3])
					{
						for (int k4 = 0; k3<CBPC[igcc4].C_num; k4++)    //右下点8BDS卫星数igc-nl*(nh-1)+1
						{
							if (CBPC[igcc1].C_PRN[k1] == CBPC[igcc4].C_PRN[k4])
							{
								BPC.C_PRN[pp] = CBPC[igcc1].C_PRN[k1];
								BPC.CPC[pp] = a1*CBPC[igcc1].CPC[k1] + a2*CBPC[igcc2].CPC[k2] + a3*CBPC[igcc3].CPC[k3] + a4*CBPC[igcc4].CPC[k4];
								pp++;
								break;
							}
						}
						break;
					}
				}
				break;
			}
		}
	}




	/************▼流动站1  dg[1]计算▼↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/

	double	M2X0, M2Y0, M2Z0;							//流动站初始坐标;
	double	M2g_swj, M2g_R, M2b_swj, M2b_R;
	double	M2G_XK, M2G_YK, M2G_ZK, M2B_XK, M2B_YK, M2B_ZK;	//初始坐标;
	int		MM2, KK2, ALL_GB2;
	//rp		rcoor2={0};
	rcoor2.X = xyz2ldz[0];
	rcoor2.Y = xyz2ldz[1];
	rcoor2.Z = xyz2ldz[2];



	for (int xunhuan = 0; xunhuan<15; xunhuan++)			//最多循环10次跳出，代替do。。。。while
	{
		double	M2gps_wj[32] = { 0 }, M2GPS_SR[32] = { 0 };	//流动站解算的gps伪距&近似距离——存储值;
		double	M2bds_wj[35] = { 0 }, M2BDS_SR[35] = { 0 };	//流动站解算的bds伪距&近似距离——存储值;
		int		M2GPRN[32] = { 0 };						//流动站gpsPRN号——存储值;
		int		M2BPRN[35] = { 0 };						//流动站bdsPRN号——存储值;
		sp		M2gps_coor = { 0 }, M2bds_coor = { 0 };		//流动站解算的gps与bds的卫星坐标——存储值;

		double	M2_gps_wj[32] = { 0 }, M2_GPS_SR[32] = { 0 };//流动站最终解算;
		double	M2_bds_wj[35] = { 0 }, M2_BDS_SR[35] = { 0 };//流动站最终解算;
		int		M2_GPRN[32] = { 0 };					//流动站最终解算;
		int		M2_BPRN[35] = { 0 };					//流动站最终解算;
		sp		M2_gps_coor = { 0 }, M2_bds_coor = { 0 };	//流动站最终解算;


		double check2_gps[32] = { 0 }, check2_bds[35] = { 0 };//检测伪距改正输出;
		int	m2 = 0, k2 = 0;								//循环回代置零;
		M2X0 = rcoor2.X;								//用于循环回代;
		M2Y0 = rcoor2.Y;
		M2Z0 = rcoor2.Z;

		for (int ii = 0; ii<M1gps_num; ii++)				//基于流动站计算卫星位置及伪距&卫地距;
		{
			M2g_swj = 0, M2g_R = 0;
			M2G_XK = 0, M2G_YK = 0, M2G_ZK = 0;
			GNSS_POS_MODULE(geph, dg, 1, M2X0, M2Y0, M2Z0, &M2g_swj, &M2g_R, &M2G_XK, &M2G_YK, &M2G_ZK, ii, 1);//dg后面的参数为站号,为了配合dg【】中的号;
			if (M2g_swj != 0 && M2g_R != 0)
			{
				M2gps_wj[m2] = M2g_swj;
				M2GPS_SR[m2] = M2g_R;
				M2GPRN[m2] = dg[1].prn[ii];
				M2gps_coor.X[m2] = M2G_XK;
				M2gps_coor.Y[m2] = M2G_YK;
				M2gps_coor.Z[m2] = M2G_ZK;

				check2_gps[m2] = M2g_R - M2g_swj;					//检测改正值正确与否,与BDS的改正值对比,注意：检测时要加入卫星钟差，以使对比与BDS的改正值是否一致,正确的应该和BDS是一致的;
				m2++;											//m为可利用GPS卫星数目
			}
		}
		for (int ii = M1gps_num + M1glo_num; ii<dg[1].nsat; ii++)		//基于流动站计算卫星位置及伪距&卫地距;
		{
			M2b_swj = 0, M2b_R = 0;
			M2B_XK = 0, M2B_YK = 0, M2B_ZK = 0;
			GNSS_POS_MODULE(geph, dg, 1, M2X0, M2Y0, M2Z0, &M2b_swj, &M2b_R, &M2B_XK, &M2B_YK, &M2B_ZK, ii, 2);//dg后面的参数为站号,为了配合dg【】中的号;
			if (M2b_swj != 0 && M2b_R != 0)
			{
				M2bds_wj[k2] = M2b_swj;
				M2BDS_SR[k2] = M2b_R;
				M2BPRN[k2] = dg[1].prn[ii];
				M2bds_coor.X[k2] = M2B_XK;
				M2bds_coor.Y[k2] = M2B_YK;
				M2bds_coor.Z[k2] = M2B_ZK;

				check2_bds[k2] = M2b_R - M2b_swj;			//检测改正值正确与否,与GPS的改正值对比,注意：检测时要加入卫星钟差，以使对比与GPS的改正值是否一致,正确的应该和GPS是一致的;
				k2++;								//m为可利用GPS卫星数目
			}
		}

		/********▼匹配伪距改正数▼********/;
		int mm2 = 0, kk2 = 0;							//该历元中流动站和改正数相匹配的数;
		for (int ii = 0; ii<m2; ii++)				//匹配从3个基准站传过来的通过反距离加权后的GPS伪距改正值;
		{
			for (int jj = 0; jj<nn; jj++)
			{
				//if (M2GPRN[ii]==BPC.G_PRN[jj]&&BPC.C_PRN[jj]!=bad_BPRN[0]&&BPC.C_PRN[jj]!=bad_BPRN[1]&&BPC.C_PRN[jj]!=bad_BPRN[2]&&BPC.C_PRN[jj]!=bad_BPRN[3]&&BPC.C_PRN[jj]!=bad_BPRN[4])
				if (M2GPRN[ii] == BPC.G_PRN[jj])
				{
					M2_gps_wj[mm2] = M2gps_wj[ii] + BPC.GPC[jj];
					M2_GPS_SR[mm2] = M2GPS_SR[ii];
					M2_GPRN[mm2] = M2GPRN[ii];
					M2_gps_coor.X[mm2] = M2gps_coor.X[ii];
					M2_gps_coor.Y[mm2] = M2gps_coor.Y[ii];
					M2_gps_coor.Z[mm2] = M2gps_coor.Z[ii];
					mm2++;
					break;
				}
			}
		}
		for (int ii = 0; ii<k2; ii++)				//匹配从3个基准站传过来的的通过反距离加权后的BDS伪距改正值;
		{
			for (int jj = 0; jj<pp; jj++)
			{
				//if (M2BPRN[ii]==BPC.C_PRN[jj]&&BPC.C_PRN[jj]!=bad_BPRN[0]&&BPC.C_PRN[jj]!=bad_BPRN[1]&&BPC.C_PRN[jj]!=bad_BPRN[2]&&BPC.C_PRN[jj]!=bad_BPRN[3]&&BPC.C_PRN[jj]!=bad_BPRN[4])
				if (M2BPRN[ii] == BPC.C_PRN[jj])
				{
					M2_bds_wj[kk2] = M2bds_wj[ii] + BPC.CPC[jj];
					M2_BDS_SR[kk2] = M2BDS_SR[ii];
					M2_BPRN[kk2] = M2BPRN[ii];
					M2_bds_coor.X[kk2] = M2bds_coor.X[ii];
					M2_bds_coor.Y[kk2] = M2bds_coor.Y[ii];
					M2_bds_coor.Z[kk2] = M2bds_coor.Z[ii];
					kk2++;
					break;
				}
			}
		}

		/************▼定位解算▼↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
		MM2 = mm2, KK2 = kk2;
		ALL_GB2 = MM2 + KK2;
		if (ALL_GB2 >= 5 && MM2>2 && KK2>2)
		{
			recei_coor(&rcoor2, M2_gps_coor, M2_gps_wj, M2_GPS_SR, M2_bds_coor, M2_bds_wj, M2_BDS_SR, ALL_GB2, MM2, KK2, &GDOP2, &PDOP2, dg[1].tg.second);//计算接收机坐标,返回位置的改正数rcoor.X、rcoor.Y、rcoor.Z;
			if (rcoor2.X != 0 && rcoor2.Y != 0 && rcoor2.Z != 0)
			{
				rcoor2.X = rcoor2.X + M2X0;			//新的接收机坐标=改正数+初值，下面判断，如果delt>0.001的话，返回do，将rcoor.X重新作为初值，循环计算到delt<0.001;
				rcoor2.Y = rcoor2.Y + M2Y0;
				rcoor2.Z = rcoor2.Z + M2Z0;
				//delt = rcoor2.X - M2X0;
				delt = sqrt(pow(rcoor2.X - M2X0,2.0)+pow(rcoor2.Y - M2Y0,2.0)+pow(rcoor2.Z - M2Z0,2.0));

				if (fabs(delt)<0.00001)
					break;
			}
			else
			{
				rcoor2.X = 0;
				rcoor2.Y = 0;
				rcoor2.Z = 0;
				rcoor2.P1 = 0;
				rcoor2.P2 = 0;
				break;
			}
		}
		else
		{
			rcoor2.X = 0;
			rcoor2.Y = 0;
			rcoor2.Z = 0;
			rcoor2.P1 = 0;
			rcoor2.P2 = 0;
			break;
		}
		//if (rcoor2.X!=0&&fabs(delt)<0.00001)
		//	break;
	}

	if (rcoor2.X != 0 && MM2 != 0 && KK2 != 0)
	{
		sate_num.KK2 = KK2;
		sate_num.MM2 = MM2;
		sate_num.ALL_GB2 = ALL_GB2;
		sate_num.delX2 = rcoor2.X;
		sate_num.delY2 = rcoor2.Y;
		sate_num.delZ2 = rcoor2.Z;
		sate_num.M2_P1 = rcoor2.P1;
		sate_num.M2_P2 = rcoor2.P2;
		sate_num.GDOP2 = GDOP2;
		sate_num.PDOP2 = PDOP2;
	}


}

void CNDGNSS::GRID_CENTER_MOVING_POS_MODULE(double  xyz2ldz[],position1 m_pos[],BS_PR_CR CBPC[], DATG dg0[], GEPH geph[MAXPRN_NUM], rp &rcoor2, Sate_NUM &sate_num, int igc)//中心点伪距差分法移动站
{
	double	delt = 1;								//do...while()限制条件中的接收机X坐标迭代控制条件
	double	GDOP2 = 0, PDOP2 = 0;
	DATG dg[5] = { 0 };
	int i = 0;
	dg[i + 1] = dg0[0];
	BS_PR_CR BPC;
	int M1gps_num = 0, M1bds_num = 0, M1glo_num = 0;	//<流动站1/2>GPS可见卫星数

	for (int ii = 0; ii<dg[1].nsat; ii++)
	{
		if (dg[1].prn[ii] <= 33)
			M1gps_num++;
		if (dg[1].prn[ii] >= 38 && dg[1].prn[ii] <= 61)
			M1glo_num++;
		if (dg[1].prn[ii] >= 161 && dg[1].prn[ii] <= 197)
			M1bds_num++;
	}


	//double	C1X, C1Y, C1Z;							//中心点1坐标
	//double	C2X, C2Y, C2Z;							//中心点2坐标
	//double	C3X, C3Y, C3Z;							//中心点3坐标
	//double	C4X, C4Y, C4Z;							//中心点4坐标
	//double MX, MY, MZ;                              //流动站坐标
	//double C1_M, C2_M, C3_M, C4_M;                  //流动站与中心点间距离
	//double s1, s2, s3, s4, s;
	//double a1, a2, a3, a4;
	////----------------------------------------------------------------------------------------------------------
	////这里因为是车载，所以流动站一直在变，那么如果流动站有坐标，就用流动站坐标到各基准站的距离，如果流动站坐标为0，就用监测站坐标，一般流动站第一次坐标为0，以后都会有值，为上一次的解得的值;
	//IOFH ih3[4] = { 0 };
	////01MNZU
	////02MNYG
	////03ANYE

	//for (int i = 0; i<4; i++)
	//{
	//	ih3[i].ntype = 5;
	//	CString strObs_type = _T("C1 L1 P2 L2 B3");
	//	memcpy(ih3[i].type, strObs_type, strObs_type.GetLength() + 1);
	//	
	//}
	//int nl=4,nh=3;//三行，四列
	//ih3[0].xyz[0] = m_pos[igc-nl*nh].x;
	//ih3[0].xyz[1] = m_pos[igc-nl*nh].y;
	//ih3[0].xyz[2] = m_pos[igc-nl*nh].z;
	//ih3[1].xyz[0] = m_pos[igc-nl*nh+1].x;
	//ih3[1].xyz[1] = m_pos[igc-nl*nh+1].y;
	//ih3[1].xyz[2] = m_pos[igc-nl*nh+1].z;
	//ih3[2].xyz[0] = m_pos[igc-nl*(nh-1)].x;
	//ih3[2].xyz[1] = m_pos[igc-nl*(nh-1)].y;
	//ih3[2].xyz[2] = m_pos[igc-nl*(nh-1)].z;
	//ih3[3].xyz[0] = m_pos[igc-nl*(nh-1)+1].x;
	//ih3[3].xyz[1] = m_pos[igc-nl*(nh-1)+1].y;
	//ih3[3].xyz[2] = m_pos[igc-nl*(nh-1)+1].z;


	//MX = xyz2ldz[0];
	//MY = xyz2ldz[1];
	//MZ = xyz2ldz[2];
	//
	//C1X = ih3[0].xyz[0];
	//C1Y = ih3[0].xyz[1];
	//C1Z = ih3[0].xyz[2];
	//C2X = ih3[1].xyz[0];
	//C2Y = ih3[1].xyz[1];
	//C2Z = ih3[1].xyz[2];
	//C3X = ih3[2].xyz[0];
	//C3Y = ih3[2].xyz[1];
	//C3Z = ih3[2].xyz[2];
	//C4X = ih3[3].xyz[0];
	//C4Y = ih3[3].xyz[1];
	//C4Z = ih3[3].xyz[2];

	//C1_M = sqrt(pow(C1X - MX, 2) + pow(C1Y - MY, 2) + pow(C1Z - MZ, 2));
	//C2_M = sqrt(pow(C2X - MX, 2) + pow(C2Y - MY, 2) + pow(C2Z - MZ, 2));
	//C3_M = sqrt(pow(C3X - MX, 2) + pow(C3Y - MY, 2) + pow(C3Z - MZ, 2));
	//C4_M = sqrt(pow(C4X - MX, 2) + pow(C4Y - MY, 2) + pow(C4Z - MZ, 2));

	//s1 = 1.0 / C1_M, s2 = 1.0 / C2_M, s3 = 1.0 / C3_M, s4 = 1.0 / C4_M;
	//s = s1 + s2 + s3 + s4;
	//a1 = s1 / s, a2 = s2 / s, a3 = s3 / s, a4 = s4 / s;
	//------------------------------------------------------------------------------------------------------------
	//------------------------------------------------------------------------------------------------------------



	for(int nn = 0 ;nn < CBPC[igc].G_num; nn++)
	{
		BPC.G_PRN[nn] = CBPC[igc].G_PRN[nn];
		BPC.GPC[nn] = CBPC[igc].GPC[nn];
	}

	for(int pp = 0 ;pp < CBPC[igc].C_num; pp++)
	{
		BPC.C_PRN[pp] = CBPC[igc].C_PRN[pp];
		BPC.CPC[pp] = CBPC[2].CPC[pp];
	}

	int pp=CBPC[igc].C_num;
	int nn=CBPC[igc].G_num;



	//▼流动站1  dg[1]计算▼↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

	double	M2X0, M2Y0, M2Z0;							//流动站初始坐标;
	double	M2g_swj, M2g_R, M2b_swj, M2b_R;
	double	M2G_XK, M2G_YK, M2G_ZK, M2B_XK, M2B_YK, M2B_ZK;	//初始坐标;
	int		MM2, KK2, ALL_GB2;
	//rp		rcoor2={0};
	rcoor2.X = xyz2ldz[0];
	rcoor2.Y = xyz2ldz[1];
	rcoor2.Z = xyz2ldz[2];



	for (int xunhuan = 0; xunhuan<15; xunhuan++)			//最多循环10次跳出，代替do。。。。while
	{
		double	M2gps_wj[32] = { 0 }, M2GPS_SR[32] = { 0 };	//流动站解算的gps伪距&近似距离——存储值;
		double	M2bds_wj[35] = { 0 }, M2BDS_SR[35] = { 0 };	//流动站解算的bds伪距&近似距离——存储值;
		int		M2GPRN[32] = { 0 };						//流动站gpsPRN号——存储值;
		int		M2BPRN[35] = { 0 };						//流动站bdsPRN号——存储值;
		sp		M2gps_coor = { 0 }, M2bds_coor = { 0 };		//流动站解算的gps与bds的卫星坐标——存储值;

		double	M2_gps_wj[32] = { 0 }, M2_GPS_SR[32] = { 0 };//流动站最终解算;
		double	M2_bds_wj[35] = { 0 }, M2_BDS_SR[35] = { 0 };//流动站最终解算;
		int		M2_GPRN[32] = { 0 };					//流动站最终解算;
		int		M2_BPRN[35] = { 0 };					//流动站最终解算;
		sp		M2_gps_coor = { 0 }, M2_bds_coor = { 0 };	//流动站最终解算;


		double check2_gps[32] = { 0 }, check2_bds[35] = { 0 };//检测伪距改正输出;
		int	m2 = 0, k2 = 0;								//循环回代置零;
		M2X0 = rcoor2.X;								//用于循环回代;
		M2Y0 = rcoor2.Y;
		M2Z0 = rcoor2.Z;

		for (int ii = 0; ii<M1gps_num; ii++)				//基于流动站计算卫星位置及伪距&卫地距;
		{
			M2g_swj = 0, M2g_R = 0;
			M2G_XK = 0, M2G_YK = 0, M2G_ZK = 0;
			GNSS_POS_MODULE(geph, dg, 1, M2X0, M2Y0, M2Z0, &M2g_swj, &M2g_R, &M2G_XK, &M2G_YK, &M2G_ZK, ii, 1);//dg后面的参数为站号,为了配合dg【】中的号;
			if (M2g_swj != 0 && M2g_R != 0)
			{
				M2gps_wj[m2] = M2g_swj;
				M2GPS_SR[m2] = M2g_R;
				M2GPRN[m2] = dg[1].prn[ii];
				M2gps_coor.X[m2] = M2G_XK;
				M2gps_coor.Y[m2] = M2G_YK;
				M2gps_coor.Z[m2] = M2G_ZK;

				check2_gps[m2] = M2g_R - M2g_swj;					//检测改正值正确与否,与BDS的改正值对比,注意：检测时要加入卫星钟差，以使对比与BDS的改正值是否一致,正确的应该和BDS是一致的;
				m2++;											//m为可利用GPS卫星数目
			}
		}
		for (int ii = M1gps_num + M1glo_num; ii<dg[1].nsat; ii++)		//基于流动站计算卫星位置及伪距&卫地距;
		{
			M2b_swj = 0, M2b_R = 0;
			M2B_XK = 0, M2B_YK = 0, M2B_ZK = 0;
			GNSS_POS_MODULE(geph, dg, 1, M2X0, M2Y0, M2Z0, &M2b_swj, &M2b_R, &M2B_XK, &M2B_YK, &M2B_ZK, ii, 2);//dg后面的参数为站号,为了配合dg【】中的号;
			if (M2b_swj != 0 && M2b_R != 0)
			{
				M2bds_wj[k2] = M2b_swj;
				M2BDS_SR[k2] = M2b_R;
				M2BPRN[k2] = dg[1].prn[ii];
				M2bds_coor.X[k2] = M2B_XK;
				M2bds_coor.Y[k2] = M2B_YK;
				M2bds_coor.Z[k2] = M2B_ZK;

				check2_bds[k2] = M2b_R - M2b_swj;			//检测改正值正确与否,与GPS的改正值对比,注意：检测时要加入卫星钟差，以使对比与GPS的改正值是否一致,正确的应该和GPS是一致的;
				k2++;								//m为可利用GPS卫星数目
			}
		}

		/////////▼匹配伪距改正数▼//////////;
		int mm2 = 0, kk2 = 0;							//该历元中流动站和改正数相匹配的数;
		for (int ii = 0; ii<m2; ii++)				//匹配从3个基准站传过来的通过反距离加权后的GPS伪距改正值;
		{
			for (int jj = 0; jj<nn; jj++)
			{
				//if (M2GPRN[ii]==BPC.G_PRN[jj]&&BPC.C_PRN[jj]!=bad_BPRN[0]&&BPC.C_PRN[jj]!=bad_BPRN[1]&&BPC.C_PRN[jj]!=bad_BPRN[2]&&BPC.C_PRN[jj]!=bad_BPRN[3]&&BPC.C_PRN[jj]!=bad_BPRN[4])
				if (M2GPRN[ii] == BPC.G_PRN[jj])
				{
					M2_gps_wj[mm2] = M2gps_wj[ii] + BPC.GPC[jj];
					M2_GPS_SR[mm2] = M2GPS_SR[ii];
					M2_GPRN[mm2] = M2GPRN[ii];
					M2_gps_coor.X[mm2] = M2gps_coor.X[ii];
					M2_gps_coor.Y[mm2] = M2gps_coor.Y[ii];
					M2_gps_coor.Z[mm2] = M2gps_coor.Z[ii];
					mm2++;
					break;
				}
			}
		}
		for (int ii = 0; ii<k2; ii++)				//匹配从3个基准站传过来的的通过反距离加权后的BDS伪距改正值;
		{
			for (int jj = 0; jj<pp; jj++)
			{
				//if (M2BPRN[ii]==BPC.C_PRN[jj]&&BPC.C_PRN[jj]!=bad_BPRN[0]&&BPC.C_PRN[jj]!=bad_BPRN[1]&&BPC.C_PRN[jj]!=bad_BPRN[2]&&BPC.C_PRN[jj]!=bad_BPRN[3]&&BPC.C_PRN[jj]!=bad_BPRN[4])
				if (M2BPRN[ii] == BPC.C_PRN[jj])
				{
					M2_bds_wj[kk2] = M2bds_wj[ii] + BPC.CPC[jj];
					M2_BDS_SR[kk2] = M2BDS_SR[ii];
					M2_BPRN[kk2] = M2BPRN[ii];
					M2_bds_coor.X[kk2] = M2bds_coor.X[ii];
					M2_bds_coor.Y[kk2] = M2bds_coor.Y[ii];
					M2_bds_coor.Z[kk2] = M2bds_coor.Z[ii];
					kk2++;
					break;
				}
			}
		}

		////////////▼定位解算▼↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
		MM2 = mm2, KK2 = kk2;
		ALL_GB2 = MM2 + KK2;
		if (ALL_GB2 >= 5 && MM2>2 && KK2>2)
		{
			recei_coor(&rcoor2, M2_gps_coor, M2_gps_wj, M2_GPS_SR, M2_bds_coor, M2_bds_wj, M2_BDS_SR, ALL_GB2, MM2, KK2, &GDOP2, &PDOP2, dg[1].tg.second);//计算接收机坐标,返回位置的改正数rcoor.X、rcoor.Y、rcoor.Z;
			if (rcoor2.X != 0 && rcoor2.Y != 0 && rcoor2.Z != 0)
			{
				rcoor2.X = rcoor2.X + M2X0;			//新的接收机坐标=改正数+初值，下面判断，如果delt>0.001的话，返回do，将rcoor.X重新作为初值，循环计算到delt<0.001;
				rcoor2.Y = rcoor2.Y + M2Y0;
				rcoor2.Z = rcoor2.Z + M2Z0;
				//delt = rcoor2.X - M2X0;
				delt = sqrt(pow(rcoor2.X - M2X0,2.0)+pow(rcoor2.Y - M2Y0,2.0)+pow(rcoor2.Z - M2Z0,2.0));

				if (fabs(delt)<0.00001)
					break;
			}
			else
			{
				rcoor2.X = 0;
				rcoor2.Y = 0;
				rcoor2.Z = 0;
				rcoor2.P1 = 0;
				rcoor2.P2 = 0;
				break;
			}
		}
		else
		{
			rcoor2.X = 0;
			rcoor2.Y = 0;
			rcoor2.Z = 0;
			rcoor2.P1 = 0;
			rcoor2.P2 = 0;
			break;
		}
		//if (rcoor2.X!=0&&fabs(delt)<0.00001)
		//	break;
	}

	if (rcoor2.X != 0 && MM2 != 0 && KK2 != 0)
	{
		sate_num.KK2 = KK2;
		sate_num.MM2 = MM2;
		sate_num.ALL_GB2 = ALL_GB2;
		sate_num.delX2 = rcoor2.X;
		sate_num.delY2 = rcoor2.Y;
		sate_num.delZ2 = rcoor2.Z;
		sate_num.M2_P1 = rcoor2.P1;
		sate_num.M2_P2 = rcoor2.P2;
		sate_num.GDOP2 = GDOP2;
		sate_num.PDOP2 = PDOP2;
	}

	//elevation_MAX=1;
	//elevation_MIN=-1;
	//m_MeandeltN= ((double) rand() / (double) RAND_MAX) *  (elevation_MAX-elevation_MIN)+elevation_MIN;
	//m_MeandeltE=((double) rand() / (double) RAND_MAX) *  (elevation_MAX-elevation_MIN)+elevation_MIN;		
	//m_MeandeltU= ((double) rand() / (double) RAND_MAX) *  (elevation_MAX-elevation_MIN)+elevation_MIN;
	//m_Meandelt40E=((double) rand() / (double) RAND_MAX) *  (elevation_MAX-elevation_MIN)+elevation_MIN;
	//m_Meandelt40N= ((double) rand() / (double) RAND_MAX) *  (elevation_MAX-elevation_MIN)+elevation_MIN;
	//m_Meandelt40U=((double) rand() / (double) RAND_MAX) *  (elevation_MAX-elevation_MIN)+elevation_MIN;
	//fprintf(m_fpNDGNSS," %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f\n",m_MeandeltN,m_MeandeltE,m_MeandeltU,m_Meandelt40N,m_Meandelt40E,m_Meandelt40U);

}

/*int代表各基站GPS、BDS卫星数 int B1n, int B2n, int B3n, int B1p, int B2p, int B3p*/

void CNDGNSS::MOVING_POS_MODULE(BS_PR_CR B1BPC, BS_PR_CR B2BPC, BS_PR_CR B3BPC, int B1n, int B2n, int B3n, int B1p, int B2p, int B3p, DATG dg0[], GEPH geph[MAXPRN_NUM], IOFH ih0[],rp &rcoor2, Sate_NUM &sate_num)
{
	double	delt = 1;								//do...while()限制条件中的接收机X坐标迭代控制条件
	double	GDOP2 = 0, PDOP2 = 0;
	DATG dg[5] = { 0 };
	IOFH ih[5] = { 0 };
	int i = 0;
	dg[i + 1] = dg0[0];
	ih[i + 1] = ih0[0];
	BS_PR_CR BPC;
	//int	B1gps_num = 0, B1bds_num = 0, B1glo_num = 0;					//基准站1当前历元GPS、BDS可见卫星数
	//int	B2gps_num = 0, B2bds_num = 0, B2glo_num = 0;					//基准站2当前历元GPS、BDS可见卫星数
	//int	B3gps_num = 0, B3bds_num = 0, B3glo_num = 0;					//基准站3当前历元GPS、BDS可见卫星数
	//for (int ii = 0; ii < dg[2].nsat; ii++)
	//{
	//	if (dg[2].prn[ii] <= 32)
	//		B1gps_num++;							//基准站1当前历元GPS可见卫星数
	//	if (dg[2].prn[ii] >= 38 && dg[2].prn[ii] <= 61)
	//		B1glo_num++;							//基准站1当前历元GLO可见卫星数
	//	if (dg[2].prn[ii] >= 161 && dg[2].prn[ii] <= 197)
	//		B1bds_num++;							//基准站1当前历元BDS可见卫星数
	//}
	//for (int ii = 0; ii < dg[3].nsat; ii++)
	//{
	//	if (dg[3].prn[ii] <= 32)
	//		B2gps_num++;							//基准站2当前历元GPS可见卫星数
	//	if (dg[3].prn[ii] >= 38 && dg[3].prn[ii] <= 61)
	//		B2glo_num++;							//基准站2当前历元GLO可见卫星数
	//	if (dg[3].prn[ii] >= 161 && dg[3].prn[ii] <= 197)
	//		B2bds_num++;							//基准站2当前历元BDS可见卫星数
	//}
	//for (int ii = 0; ii < dg[4].nsat; ii++)
	//{
	//	if (dg[4].prn[ii] <= 32)
	//		B3gps_num++;							//基准站3当前历元GPS可见卫星数
	//	if (dg[4].prn[ii] >= 38 && dg[4].prn[ii] <= 61)
	//		B3glo_num++;							//基准站3当前历元GLO可见卫星数
	//	if (dg[4].prn[ii] >= 161 && dg[4].prn[ii] <= 197)
	//		B3bds_num++;							//基准站3当前历元BDS可见卫星数
	//}

	int M1gps_num = 0, M1bds_num = 0, M1glo_num = 0;	//<流动站1/2>GPS可见卫星数

	for (int ii = 0; ii<dg[1].nsat; ii++)
	{
		if (dg[1].prn[ii] <= 33)
			M1gps_num++;
		if (dg[1].prn[ii] >= 38 && dg[1].prn[ii] <= 61)
			M1glo_num++;
		if (dg[1].prn[ii] >= 161 && dg[1].prn[ii] <= 197)
			M1bds_num++;
	}


	double	B1X, B1Y, B1Z;							//基准站1坐标
	double	B2X, B2Y, B2Z;							//基准站2坐标
	double	B3X, B3Y, B3Z;							//基准站3坐标
	double MX, MY, MZ;
	double B1_M, B2_M, B3_M;
	double s1, s2, s3, s;
	double a1, a2, a3;
	//----------------------------------------------------------------------------------------------------------
	//这里因为是车载，所以流动站一直在变，那么如果流动站有坐标，就用流动站坐标到各基准站的距离，如果流动站坐标为0，就用监测站坐标，一般流动站第一次坐标为0，以后都会有值，为上一次的解得的值;
	IOFH ih3[3] = { 0 };
	//01MNZU
	//02MNYG
	//03ANYE
	double stationXYZ[3*3] =
	{

		-1337148.6337, 5287223.7322, 3297228.9847,
		-1384670.1809, 5268187.9805, 3307858.5096,
		-1355219.3322, 5324431.7237, 3229574.5390

	};

	for (int i = 0; i<3; i++)
	{
		ih3[i].ntype = 5;
		CString strObs_type = _T("C1 L1 P2 L2 B3");
		memcpy(ih3[i].type, strObs_type, strObs_type.GetLength() + 1);
		ih3[i].xyz[0] = stationXYZ[3*i+0];
		ih3[i].xyz[1] = stationXYZ[3*i+1];
		ih3[i].xyz[2] = stationXYZ[3*i+2];

	}



	MX = ih[1].xyz[0];
	MY = ih[1].xyz[1];
	MZ = ih[1].xyz[2];

	B1X = ih3[0].xyz[0];
	B1Y = ih3[0].xyz[1];
	B1Z = ih3[0].xyz[2];
	B2X = ih3[1].xyz[0];
	B2Y = ih3[1].xyz[1];
	B2Z = ih3[1].xyz[2];
	B3X = ih3[2].xyz[0];
	B3Y = ih3[2].xyz[1];
	B3Z = ih3[2].xyz[2];


	B1_M = sqrt(pow(B1X - MX, 2) + pow(B1Y - MY, 2) + pow(B1Z - MZ, 2));
	B2_M = sqrt(pow(B2X - MX, 2) + pow(B2Y - MY, 2) + pow(B2Z - MZ, 2));
	B3_M = sqrt(pow(B3X - MX, 2) + pow(B3Y - MY, 2) + pow(B3Z - MZ, 2));

	s1 = 1.0 / B1_M, s2 = 1.0 / B2_M, s3 = 1.0 / B3_M;
	s = s1 + s2 + s3;
	a1 = s1 / s, a2 = s2 / s, a3 = s3 / s;
	//------------------------------------------------------------------------------------------------------------
	//------------------------------------------------------------------------------------------------------------



	int nn = 0, pp = 0;
	for (int k1 = 0; k1<B1n; k1++)						//主控站GPS卫星数
	{
		for (int k2 = 0; k2<B2n; k2++)					//监测站1GPS卫星数
		{
			if (B1BPC.G_PRN[k1] == B2BPC.G_PRN[k2])
			{
				for (int k3 = 0; k3<B3n; k3++)			//监测站2GPS卫星数
				{
					if (B1BPC.G_PRN[k1] == B3BPC.G_PRN[k3])
					{

						BPC.G_PRN[nn] = B1BPC.G_PRN[k1];//反距离加权后的BPC除伪距改正项外，其他与主控站一致;
						BPC.GPC[nn] = a1*B1BPC.GPC[k1] + a2*B2BPC.GPC[k2] + a3*B3BPC.GPC[k3];

						nn++;
						break;
					}
				}
				break;
			}
		}
	}
	for (int k1 = 0; k1<B1p; k1++)						//主控站BDS卫星数
	{
		for (int k2 = 0; k2<B2p; k2++)					//监测站1BDS卫星数
		{
			if (B1BPC.C_PRN[k1] == B2BPC.C_PRN[k2])
			{
				for (int k3 = 0; k3<B3p; k3++)			//监测站2BDS卫星数
				{
					if (B1BPC.C_PRN[k1] == B3BPC.C_PRN[k3])
					{

						BPC.C_PRN[pp] = B1BPC.C_PRN[k1];
						BPC.CPC[pp] = a1*B1BPC.CPC[k1] + a2*B2BPC.CPC[k2] + a3*B3BPC.CPC[k3];
						pp++;
						break;
					}
				}
				break;
			}
		}
	}




	/************▼流动站1  dg[1]计算▼↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/

	double	M2X0, M2Y0, M2Z0;							//流动站初始坐标;
	double	M2g_swj, M2g_R, M2b_swj, M2b_R;
	double	M2G_XK, M2G_YK, M2G_ZK, M2B_XK, M2B_YK, M2B_ZK;	//初始坐标;
	int		MM2, KK2, ALL_GB2;
	//rp		rcoor2={0};
	rcoor2.X = ih[1].xyz[0];
	rcoor2.Y = ih[1].xyz[1];
	rcoor2.Z = ih[1].xyz[2];



	for (int xunhuan = 0; xunhuan<15; xunhuan++)			//最多循环10次跳出，代替do。。。。while
	{
		double	M2gps_wj[32] = { 0 }, M2GPS_SR[32] = { 0 };	//流动站解算的gps伪距&近似距离——存储值;
		double	M2bds_wj[35] = { 0 }, M2BDS_SR[35] = { 0 };	//流动站解算的bds伪距&近似距离——存储值;
		int		M2GPRN[32] = { 0 };						//流动站gpsPRN号——存储值;
		int		M2BPRN[35] = { 0 };						//流动站bdsPRN号——存储值;
		sp		M2gps_coor = { 0 }, M2bds_coor = { 0 };		//流动站解算的gps与bds的卫星坐标——存储值;

		double	M2_gps_wj[32] = { 0 }, M2_GPS_SR[32] = { 0 };//流动站最终解算;
		double	M2_bds_wj[35] = { 0 }, M2_BDS_SR[35] = { 0 };//流动站最终解算;
		int		M2_GPRN[32] = { 0 };					//流动站最终解算;
		int		M2_BPRN[35] = { 0 };					//流动站最终解算;
		sp		M2_gps_coor = { 0 }, M2_bds_coor = { 0 };	//流动站最终解算;


		double check2_gps[32] = { 0 }, check2_bds[35] = { 0 };//检测伪距改正输出;
		int	m2 = 0, k2 = 0;								//循环回代置零;
		M2X0 = rcoor2.X;								//用于循环回代;
		M2Y0 = rcoor2.Y;
		M2Z0 = rcoor2.Z;

		for (int ii = 0; ii<M1gps_num; ii++)				//基于流动站计算卫星位置及伪距&卫地距;
		{
			M2g_swj = 0, M2g_R = 0;
			M2G_XK = 0, M2G_YK = 0, M2G_ZK = 0;
			GNSS_POS_MODULE(geph, dg, 1, M2X0, M2Y0, M2Z0, &M2g_swj, &M2g_R, &M2G_XK, &M2G_YK, &M2G_ZK, ii, 1);//dg后面的参数为站号,为了配合dg【】中的号;
			if (M2g_swj != 0 && M2g_R != 0)
			{
				M2gps_wj[m2] = M2g_swj;
				M2GPS_SR[m2] = M2g_R;
				M2GPRN[m2] = dg[1].prn[ii];
				M2gps_coor.X[m2] = M2G_XK;
				M2gps_coor.Y[m2] = M2G_YK;
				M2gps_coor.Z[m2] = M2G_ZK;

				check2_gps[m2] = M2g_R - M2g_swj;					//检测改正值正确与否,与BDS的改正值对比,注意：检测时要加入卫星钟差，以使对比与BDS的改正值是否一致,正确的应该和BDS是一致的;
				m2++;											//m为可利用GPS卫星数目
			}
		}
		for (int ii = M1gps_num + M1glo_num; ii<dg[1].nsat; ii++)		//基于流动站计算卫星位置及伪距&卫地距;
		{
			M2b_swj = 0, M2b_R = 0;
			M2B_XK = 0, M2B_YK = 0, M2B_ZK = 0;
			GNSS_POS_MODULE(geph, dg, 1, M2X0, M2Y0, M2Z0, &M2b_swj, &M2b_R, &M2B_XK, &M2B_YK, &M2B_ZK, ii, 2);//dg后面的参数为站号,为了配合dg【】中的号;
			if (M2b_swj != 0 && M2b_R != 0)
			{
				M2bds_wj[k2] = M2b_swj;
				M2BDS_SR[k2] = M2b_R;
				M2BPRN[k2] = dg[1].prn[ii];
				M2bds_coor.X[k2] = M2B_XK;
				M2bds_coor.Y[k2] = M2B_YK;
				M2bds_coor.Z[k2] = M2B_ZK;

				check2_bds[k2] = M2b_R - M2b_swj;			//检测改正值正确与否,与GPS的改正值对比,注意：检测时要加入卫星钟差，以使对比与GPS的改正值是否一致,正确的应该和GPS是一致的;
				k2++;								//m为可利用GPS卫星数目
			}
		}

		/********▼匹配伪距改正数▼********/;
		int mm2 = 0, kk2 = 0;							//该历元中流动站和改正数相匹配的数;
		for (int ii = 0; ii<m2; ii++)				//匹配从3个基准站传过来的通过反距离加权后的GPS伪距改正值;
		{
			for (int jj = 0; jj<nn; jj++)
			{
				//if (M2GPRN[ii]==BPC.G_PRN[jj]&&BPC.C_PRN[jj]!=bad_BPRN[0]&&BPC.C_PRN[jj]!=bad_BPRN[1]&&BPC.C_PRN[jj]!=bad_BPRN[2]&&BPC.C_PRN[jj]!=bad_BPRN[3]&&BPC.C_PRN[jj]!=bad_BPRN[4])
				if (M2GPRN[ii] == BPC.G_PRN[jj])
				{
					M2_gps_wj[mm2] = M2gps_wj[ii] + BPC.GPC[jj];
					M2_GPS_SR[mm2] = M2GPS_SR[ii];
					M2_GPRN[mm2] = M2GPRN[ii];
					M2_gps_coor.X[mm2] = M2gps_coor.X[ii];
					M2_gps_coor.Y[mm2] = M2gps_coor.Y[ii];
					M2_gps_coor.Z[mm2] = M2gps_coor.Z[ii];
					mm2++;
					break;
				}
			}
		}
		for (int ii = 0; ii<k2; ii++)				//匹配从3个基准站传过来的的通过反距离加权后的BDS伪距改正值;
		{
			for (int jj = 0; jj<pp; jj++)
			{
				//if (M2BPRN[ii]==BPC.C_PRN[jj]&&BPC.C_PRN[jj]!=bad_BPRN[0]&&BPC.C_PRN[jj]!=bad_BPRN[1]&&BPC.C_PRN[jj]!=bad_BPRN[2]&&BPC.C_PRN[jj]!=bad_BPRN[3]&&BPC.C_PRN[jj]!=bad_BPRN[4])
				if (M2BPRN[ii] == BPC.C_PRN[jj])
				{
					M2_bds_wj[kk2] = M2bds_wj[ii] + BPC.CPC[jj];
					M2_BDS_SR[kk2] = M2BDS_SR[ii];
					M2_BPRN[kk2] = M2BPRN[ii];
					M2_bds_coor.X[kk2] = M2bds_coor.X[ii];
					M2_bds_coor.Y[kk2] = M2bds_coor.Y[ii];
					M2_bds_coor.Z[kk2] = M2bds_coor.Z[ii];
					kk2++;
					break;
				}
			}
		}

		/************▼定位解算▼↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
		MM2 = mm2, KK2 = kk2;
		ALL_GB2 = MM2 + KK2;
		if (ALL_GB2 >= 5 && MM2>2 && KK2>2)
		{
			recei_coor(&rcoor2, M2_gps_coor, M2_gps_wj, M2_GPS_SR, M2_bds_coor, M2_bds_wj, M2_BDS_SR, ALL_GB2, MM2, KK2, &GDOP2, &PDOP2, dg[1].tg.second);//计算接收机坐标,返回位置的改正数rcoor.X、rcoor.Y、rcoor.Z;
			if (rcoor2.X != 0 && rcoor2.Y != 0 && rcoor2.Z != 0)
			{
				rcoor2.X = rcoor2.X + M2X0;			//新的接收机坐标=改正数+初值，下面判断，如果delt>0.001的话，返回do，将rcoor.X重新作为初值，循环计算到delt<0.001;
				rcoor2.Y = rcoor2.Y + M2Y0;
				rcoor2.Z = rcoor2.Z + M2Z0;
				//delt = rcoor2.X - M2X0;
				delt = sqrt(pow(rcoor2.X - M2X0,2.0)+pow(rcoor2.Y - M2Y0,2.0)+pow(rcoor2.Z - M2Z0,2.0));

				if (fabs(delt)<0.00001)
					break;
			}
			else
			{
				rcoor2.X = 0;
				rcoor2.Y = 0;
				rcoor2.Z = 0;
				rcoor2.P1 = 0;
				rcoor2.P2 = 0;
				break;
			}
		}
		else
		{
			rcoor2.X = 0;
			rcoor2.Y = 0;
			rcoor2.Z = 0;
			rcoor2.P1 = 0;
			rcoor2.P2 = 0;
			break;
		}
		//if (rcoor2.X!=0&&fabs(delt)<0.00001)
		//	break;
	}

	if (rcoor2.X != 0 && MM2 != 0 && KK2 != 0)
	{
		sate_num.KK2 = KK2;
		sate_num.MM2 = MM2;
		sate_num.ALL_GB2 = ALL_GB2;
		sate_num.delX2 = rcoor2.X;
		sate_num.delY2 = rcoor2.Y;
		sate_num.delZ2 = rcoor2.Z;
		sate_num.M2_P1 = rcoor2.P1;
		sate_num.M2_P2 = rcoor2.P2;
		sate_num.GDOP2 = GDOP2;
		sate_num.PDOP2 = PDOP2;
	}

	//elevation_MAX=1;
	//elevation_MIN=-1;
	//m_MeandeltN= ((double) rand() / (double) RAND_MAX) *  (elevation_MAX-elevation_MIN)+elevation_MIN;
	//m_MeandeltE=((double) rand() / (double) RAND_MAX) *  (elevation_MAX-elevation_MIN)+elevation_MIN;		
	//m_MeandeltU= ((double) rand() / (double) RAND_MAX) *  (elevation_MAX-elevation_MIN)+elevation_MIN;
	//m_Meandelt40E=((double) rand() / (double) RAND_MAX) *  (elevation_MAX-elevation_MIN)+elevation_MIN;
	//m_Meandelt40N= ((double) rand() / (double) RAND_MAX) *  (elevation_MAX-elevation_MIN)+elevation_MIN;
	//m_Meandelt40U=((double) rand() / (double) RAND_MAX) *  (elevation_MAX-elevation_MIN)+elevation_MIN;
	//fprintf(m_fpNDGNSS," %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f\n",m_MeandeltN,m_MeandeltE,m_MeandeltU,m_Meandelt40N,m_Meandelt40E,m_Meandelt40U);


}
void CNDGNSS::MOVING_POS_MODULE4(double  xyz2ldz6[],BS_PR_CR BBPC[], DATG dg0[], GEPH geph[MAXPRN_NUM], rp &rcoor2, Sate_NUM &sate_num,int Bn[],int Bp[])
{
	double	delt = 1;								//do...while()限制条件中的接收机X坐标迭代控制条件
	double	GDOP2 = 0, PDOP2 = 0;
	DATG dg[5] = { 0 };
	int i = 0;
	dg[i + 1] = dg0[0];
	BS_PR_CR BPC={0};
	int M1gps_num = 0, M1bds_num = 0, M1glo_num = 0;	//<流动站1/2>GPS可见卫星数

	for (int ii = 0; ii<dg[1].nsat; ii++)
	{
		if (dg[1].prn[ii] <= 33)
			M1gps_num++;
		if (dg[1].prn[ii] >= 38 && dg[1].prn[ii] <= 61)
			M1glo_num++;
		if (dg[1].prn[ii] >= 161 && dg[1].prn[ii] <= 197)
			M1bds_num++;
	}


	double	C1X, C1Y, C1Z;							//网格点1坐标
	double	C2X, C2Y, C2Z;							//网格点2坐标
	double	C3X, C3Y, C3Z;							//网格点3坐标
	double	C4X, C4Y, C4Z;							//网格点4坐标
	double MX, MY, MZ;                              //流动站坐标
	double C1_M, C2_M, C3_M, C4_M;                  //流动站与中心点间距离
	double s1, s2, s3, s4, s;
	double a[5]={0};
	//----------------------------------------------------------------------------------------------------------
	//这里因为是车载，所以流动站一直在变，那么如果流动站有坐标，就用流动站坐标到各基准站的距离，如果流动站坐标为0，就用监测站坐标，一般流动站第一次坐标为0，以后都会有值，为上一次的解得的值;
	IOFH ih3[4] = { 0 };
	//01MNZU
	//02MNYG
	//03ANYE



	double stationXYZ[4*3] =
	{
		-1337148.6337,5287223.7322,3297228.9847,
		-1355219.3322,5324431.7237,3229574.5390,
		-1384670.1809,5268187.9805,3307858.5096,
		-1386985.5690,5292102.2012,3268565.3229 



		/*-1337148.6337, 5287223.7322, 3297228.9847,
		-1460122.5642, 5326238.9128, 3180485.8097,
		-1386985.5690, 5292102.2012, 3268565.3229,
		-1385477.5551, 5382919.3157, 3118352.9324*/
	};

	for (int i = 0; i<4; i++)
	{
		ih3[i].ntype = 5;
		CString strObs_type = _T("C1 L1 P2 L2 B3");
		memcpy(ih3[i].type, strObs_type, strObs_type.GetLength() + 1);
		ih3[i].xyz[0] = stationXYZ[3*i+0];
		ih3[i].xyz[1] = stationXYZ[3*i+1];
		ih3[i].xyz[2] = stationXYZ[3*i+2];

	}

	MX = xyz2ldz6[0];
	MY = xyz2ldz6[1];
	MZ = xyz2ldz6[2];

	C1X = ih3[0].xyz[0];
	C1Y = ih3[0].xyz[1];
	C1Z = ih3[0].xyz[2];
	C2X = ih3[1].xyz[0];
	C2Y = ih3[1].xyz[1];
	C2Z = ih3[1].xyz[2];
	C3X = ih3[2].xyz[0];
	C3Y = ih3[2].xyz[1];
	C3Z = ih3[2].xyz[2];
	C4X = ih3[3].xyz[0];
	C4Y = ih3[3].xyz[1];
	C4Z = ih3[3].xyz[2];

	C1_M = sqrt(pow(C1X - MX, 2) + pow(C1Y - MY, 2) + pow(C1Z - MZ, 2));
	C2_M = sqrt(pow(C2X - MX, 2) + pow(C2Y - MY, 2) + pow(C2Z - MZ, 2));
	C3_M = sqrt(pow(C3X - MX, 2) + pow(C3Y - MY, 2) + pow(C3Z - MZ, 2));
	C4_M = sqrt(pow(C4X - MX, 2) + pow(C4Y - MY, 2) + pow(C4Z - MZ, 2));

	s1 = 1.0 / C1_M; s2 = 1.0 / C2_M; s3 = 1.0 / C3_M; s4 = 1.0 / C4_M;
	s = s1 + s2 + s3 + s4;
	a[1] = s1 / s; a[2] = s2 / s; a[3] = s3 / s; a[4] = s4 / s;
	//------------------------------------------------------------------------------------------------------------
	//------------------------------------------------------------------------------------------------------------



	int k[10]={0}, nn = 0, pp = 0;
	for ( k[1] = 0; k[1]<Bn[1]; k[1]++)						//主控站1GPS卫星数
	{
		for ( k[2] = 0; k[2]<Bn[2]; k[2]++)					//监测站2GPS卫星数
		{
			if (BBPC[1].G_PRN[k[1]] == BBPC[2].G_PRN[k[2]])
			{
				for ( k[3] = 0; k[3]<Bn[3]; k[3]++)			//监测站3GPS卫星数
				{
					if (BBPC[1].G_PRN[k[1]] == BBPC[3].G_PRN[k[3]])
					{
						for ( k[4] = 0; k[4]<Bn[4]; k[4]++)					//监测站4GPS卫星数
						{
							if (BBPC[1].G_PRN[k[1]] == BBPC[4].G_PRN[k[4]])
							{
								//for ( k[5] = 0; k[5]<Bn[5]; k[5]++)			//监测站5GPS卫星数
								//{
								//	if (BBPC[1].G_PRN[k[1]] == BBPC[5].G_PRN[k[5]])
								//	{
								//		for ( k[6] = 0; k[6]<Bn[6]; k[6]++)			//监测站6GPS卫星数
								//		{
								//			if (BBPC[1].G_PRN[k[1]] == BBPC[6].G_PRN[k[6]])
								//			{
								BPC.G_PRN[nn] = BBPC[1].G_PRN[k[1]];//反距离加权后的BPC除伪距改正项外，其他与主控站一致;
								for(int njjzz=1;njjzz< 5;njjzz++){BPC.GPC[nn] += a[njjzz]*BBPC[njjzz].GPC[k[njjzz]];}//NO_JZZ个基准站

								nn++;
								break;
								//			}
								//		}
								//		break;
								//	}
								//}
								//break;
							}
						}
						break;
					}
				}
				break;
			}
		}
	}
	for ( k[1] = 0; k[1]<Bp[1]; k[1]++)						//主控站1BDS卫星数
	{
		for ( k[2] = 0; k[2]<Bp[2]; k[2]++)					//监测站2BDS卫星数
		{
			if (BBPC[1].C_PRN[k[1]] == BBPC[2].C_PRN[k[2]])
			{
				for ( k[3] = 0; k[3]<Bp[3]; k[3]++)			//监测站3BDS卫星数
				{
					if (BBPC[1].C_PRN[k[1]] == BBPC[3].C_PRN[k[3]])
					{
						for ( k[4] = 0; k[4]<Bp[4]; k[4]++)					//监测站4BDS卫星数
						{
							if (BBPC[1].C_PRN[k[1]] == BBPC[4].C_PRN[k[4]])
							{
								//for ( k[5] = 0; k[5]<Bp[5]; k[5]++)			//监测站5BDS卫星数
								//{
								//	if (BBPC[1].C_PRN[k[1]] == BBPC[5].C_PRN[k[5]])
								//	{
								//		for ( k[6] = 0; k[6]<Bp[6]; k[6]++)			//监测站6BDS卫星数
								//		{
								//			if (BBPC[1].C_PRN[k[1]] == BBPC[6].C_PRN[k[6]])
								//			{
								BPC.C_PRN[pp] = BBPC[1].C_PRN[k[1]];//反距离加权后的BPC除伪距改正项外，其他与主控站一致;
								for(int njjzz=1;njjzz< 5;njjzz++){BPC.CPC[pp] += a[njjzz]*BBPC[njjzz].CPC[k[njjzz]];}

								pp++;
								break;
								//			}
								//		}
								//		break;
								//	}
								//}
								//break;
							}
						}
						break;
					}
				}
				break;
			}
		}
	}




	/************▼流动站1  dg[1]计算▼↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/

	double	M2X0, M2Y0, M2Z0;							//流动站初始坐标;
	double	M2g_swj, M2g_R, M2b_swj, M2b_R;
	double	M2G_XK, M2G_YK, M2G_ZK, M2B_XK, M2B_YK, M2B_ZK;	//初始坐标;
	int		MM2, KK2, ALL_GB2;
	//rp		rcoor2={0};
	rcoor2.X = xyz2ldz6[0];
	rcoor2.Y = xyz2ldz6[1];
	rcoor2.Z = xyz2ldz6[2];

	int xunhuan=0;
	do		//最多循环10次跳出，代替do。。。。while
	{ 


		if( xunhuan>14)	{break;}		//最多循环10次跳出，代替do。。。。while
		xunhuan++;
		//for (int xunhuan = 0; xunhuan<15; xunhuan++)			//最多循环10次跳出，代替do。。。。while
		//{
		double	M2gps_wj[32] = { 0 }, M2GPS_SR[32] = { 0 };	//流动站解算的gps伪距&近似距离——存储值;
		double	M2bds_wj[35] = { 0 }, M2BDS_SR[35] = { 0 };	//流动站解算的bds伪距&近似距离——存储值;
		int		M2GPRN[32] = { 0 };						//流动站gpsPRN号——存储值;
		int		M2BPRN[35] = { 0 };						//流动站bdsPRN号——存储值;
		sp		M2gps_coor = { 0 }, M2bds_coor = { 0 };		//流动站解算的gps与bds的卫星坐标——存储值;

		double	M2_gps_wj[32] = { 0 }, M2_GPS_SR[32] = { 0 };//流动站最终解算;
		double	M2_bds_wj[35] = { 0 }, M2_BDS_SR[35] = { 0 };//流动站最终解算;
		int		M2_GPRN[32] = { 0 };					//流动站最终解算;
		int		M2_BPRN[35] = { 0 };					//流动站最终解算;
		sp		M2_gps_coor = { 0 }, M2_bds_coor = { 0 };	//流动站最终解算;


		double check2_gps[32] = { 0 }, check2_bds[35] = { 0 };//检测伪距改正输出;
		int	m2 = 0, k2 = 0;								//循环回代置零;
		M2X0 = rcoor2.X;								//用于循环回代;
		M2Y0 = rcoor2.Y;
		M2Z0 = rcoor2.Z;

		for (int ii = 0; ii<M1gps_num; ii++)				//基于流动站计算卫星位置及伪距&卫地距;
		{
			M2g_swj = 0, M2g_R = 0;
			M2G_XK = 0, M2G_YK = 0, M2G_ZK = 0;
			GNSS_POS_MODULE(geph, dg, 1, M2X0, M2Y0, M2Z0, &M2g_swj, &M2g_R, &M2G_XK, &M2G_YK, &M2G_ZK, ii, 1);//dg后面的参数为站号,为了配合dg【】中的号;
			if (M2g_swj != 0 && M2g_R != 0)
			{
				M2gps_wj[m2] = M2g_swj;
				M2GPS_SR[m2] = M2g_R;
				M2GPRN[m2] = dg[1].prn[ii];
				M2gps_coor.X[m2] = M2G_XK;
				M2gps_coor.Y[m2] = M2G_YK;
				M2gps_coor.Z[m2] = M2G_ZK;

				check2_gps[m2] = M2g_R - M2g_swj;					//检测改正值正确与否,与BDS的改正值对比,注意：检测时要加入卫星钟差，以使对比与BDS的改正值是否一致,正确的应该和BDS是一致的;
				m2++;											//m为可利用GPS卫星数目
			}
		}
		for (int ii = M1gps_num + M1glo_num; ii<dg[1].nsat; ii++)		//基于流动站计算卫星位置及伪距&卫地距;
		{
			M2b_swj = 0, M2b_R = 0;
			M2B_XK = 0, M2B_YK = 0, M2B_ZK = 0;
			GNSS_POS_MODULE(geph, dg, 1, M2X0, M2Y0, M2Z0, &M2b_swj, &M2b_R, &M2B_XK, &M2B_YK, &M2B_ZK, ii, 2);//dg后面的参数为站号,为了配合dg【】中的号;
			if (M2b_swj != 0 && M2b_R != 0)
			{
				M2bds_wj[k2] = M2b_swj;
				M2BDS_SR[k2] = M2b_R;
				M2BPRN[k2] = dg[1].prn[ii];
				M2bds_coor.X[k2] = M2B_XK;
				M2bds_coor.Y[k2] = M2B_YK;
				M2bds_coor.Z[k2] = M2B_ZK;

				check2_bds[k2] = M2b_R - M2b_swj;			//检测改正值正确与否,与GPS的改正值对比,注意：检测时要加入卫星钟差，以使对比与GPS的改正值是否一致,正确的应该和GPS是一致的;
				k2++;								//m为可利用GPS卫星数目
			}
		}

		/********▼匹配伪距改正数▼********/;
		int mm2 = 0, kk2 = 0;							//该历元中流动站和改正数相匹配的数;
		for (int ii = 0; ii<m2; ii++)				//匹配从3个基准站传过来的通过反距离加权后的GPS伪距改正值;
		{
			for (int jj = 0; jj<nn; jj++)
			{
				//if (M2GPRN[ii]==BPC.G_PRN[jj]&&BPC.C_PRN[jj]!=bad_BPRN[0]&&BPC.C_PRN[jj]!=bad_BPRN[1]&&BPC.C_PRN[jj]!=bad_BPRN[2]&&BPC.C_PRN[jj]!=bad_BPRN[3]&&BPC.C_PRN[jj]!=bad_BPRN[4])
				if (M2GPRN[ii] == BPC.G_PRN[jj])
				{
					M2_gps_wj[mm2] = M2gps_wj[ii] + BPC.GPC[jj];
					M2_GPS_SR[mm2] = M2GPS_SR[ii];
					M2_GPRN[mm2] = M2GPRN[ii];
					M2_gps_coor.X[mm2] = M2gps_coor.X[ii];
					M2_gps_coor.Y[mm2] = M2gps_coor.Y[ii];
					M2_gps_coor.Z[mm2] = M2gps_coor.Z[ii];
					mm2++;
					break;
				}
			}
		}
		for (int ii = 0; ii<k2; ii++)				//匹配从3个基准站传过来的的通过反距离加权后的BDS伪距改正值;
		{
			for (int jj = 0; jj<pp; jj++)
			{
				//if (M2BPRN[ii]==BPC.C_PRN[jj]&&BPC.C_PRN[jj]!=bad_BPRN[0]&&BPC.C_PRN[jj]!=bad_BPRN[1]&&BPC.C_PRN[jj]!=bad_BPRN[2]&&BPC.C_PRN[jj]!=bad_BPRN[3]&&BPC.C_PRN[jj]!=bad_BPRN[4])
				if (M2BPRN[ii] == BPC.C_PRN[jj])
				{
					M2_bds_wj[kk2] = M2bds_wj[ii] + BPC.CPC[jj];
					M2_BDS_SR[kk2] = M2BDS_SR[ii];
					M2_BPRN[kk2] = M2BPRN[ii];
					M2_bds_coor.X[kk2] = M2bds_coor.X[ii];
					M2_bds_coor.Y[kk2] = M2bds_coor.Y[ii];
					M2_bds_coor.Z[kk2] = M2bds_coor.Z[ii];
					kk2++;
					break;
				}
			}
		}

		/************▼定位解算▼↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
		MM2 = mm2, KK2 = kk2;
		ALL_GB2 = MM2 + KK2;
		if (ALL_GB2 >= 5 && MM2>2 && KK2>2)
		{
			recei_coor(&rcoor2, M2_gps_coor, M2_gps_wj, M2_GPS_SR, M2_bds_coor, M2_bds_wj, M2_BDS_SR, ALL_GB2, MM2, KK2, &GDOP2, &PDOP2, dg[1].tg.second);//计算接收机坐标,返回位置的改正数rcoor.X、rcoor.Y、rcoor.Z;
			if (rcoor2.X != 0 && rcoor2.Y != 0 && rcoor2.Z != 0)
			{
				rcoor2.X = rcoor2.X + M2X0;			//新的接收机坐标=改正数+初值，下面判断，如果delt>0.001的话，返回do，将rcoor.X重新作为初值，循环计算到delt<0.001;
				rcoor2.Y = rcoor2.Y + M2Y0;
				rcoor2.Z = rcoor2.Z + M2Z0;
				//delt = rcoor2.X - M2X0;
				delt = sqrt(pow(rcoor2.X - M2X0,2.0)+pow(rcoor2.Y - M2Y0,2.0)+pow(rcoor2.Z - M2Z0,2.0));

				/*if (fabs(delt)<0.00001)
				break;*/
			}
			else
			{
				rcoor2.X = 0;
				rcoor2.Y = 0;
				rcoor2.Z = 0;
				rcoor2.P1 = 0;
				rcoor2.P2 = 0;
				break;
			}
		}

		else if (MM2 >= 4 && KK2==0)//大于4时，RMS才有值;
		{
			recei_coor_single(&rcoor2,M2_gps_coor,M2_gps_wj,&MM2,M2_GPS_SR,&GDOP2,&PDOP2);//计算接收机坐标,返回位置的改正数rcoor.X、rcoor.Y、rcoor.Z;
			if(rcoor2.X==0&&rcoor2.Y==0&&rcoor2.Z==0)//不能循环太多，比如循环39次，这里的rcoor.X==0&&rcoor.Y==0&&rcoor.Z==0，但是是正确的
			{
				rcoor2.X = 0;
				rcoor2.Y = 0;
				rcoor2.Z = 0;
				rcoor2.P1 = 0;
				rcoor2.P2 = 0;
				break;
			}
			else
			{
				rcoor2.X = rcoor2.X + M2X0;			//新的接收机坐标=改正数+初值，下面判断，如果delt>0.001的话，返回do，将rcoor.X重新作为初值，循环计算到delt<0.001;
				rcoor2.Y = rcoor2.Y + M2Y0;
				rcoor2.Z = rcoor2.Z + M2Z0;
				//delt = rcoor2.X - M2X0;
				delt = sqrt(pow(rcoor2.X - M2X0,2.0)+pow(rcoor2.Y - M2Y0,2.0)+pow(rcoor2.Z - M2Z0,2.0));

				/*	if (fabs(delt)<0.00001)
				break;*/

			}
		}
		else if (MM2 ==0 && KK2>=4)//大于4时，RMS才有值;
		{
			recei_coor_single(&rcoor2,M2_bds_coor,M2_bds_wj,&KK2,M2_BDS_SR,&GDOP2,&PDOP2);//计算接收机坐标,返回位置的改正数rcoor.X、rcoor.Y、rcoor.Z;
			if(rcoor2.X==0&&rcoor2.Y==0&&rcoor2.Z==0)//不能循环太多，比如循环39次，这里的rcoor.X==0&&rcoor.Y==0&&rcoor.Z==0，但是是正确的
			{
				rcoor2.X = 0;
				rcoor2.Y = 0;
				rcoor2.Z = 0;
				rcoor2.P1 = 0;
				rcoor2.P2 = 0;
				break;
			}
			else
			{
				rcoor2.X = rcoor2.X + M2X0;			//新的接收机坐标=改正数+初值，下面判断，如果delt>0.001的话，返回do，将rcoor.X重新作为初值，循环计算到delt<0.001;
				rcoor2.Y = rcoor2.Y + M2Y0;
				rcoor2.Z = rcoor2.Z + M2Z0;
				//delt = rcoor2.X - M2X0;
				delt = sqrt(pow(rcoor2.X - M2X0,2.0)+pow(rcoor2.Y - M2Y0,2.0)+pow(rcoor2.Z - M2Z0,2.0));

				/*if (fabs(delt)<0.00001)
				break;*/

			}
		}

		else
		{
			rcoor2.X = 0;
			rcoor2.Y = 0;
			rcoor2.Z = 0;
			rcoor2.P1 = 0;
			rcoor2.P2 = 0;
			break;
		}
		//if (rcoor2.X!=0&&fabs(delt)<0.00001)
		//	break;
	}while(delt>0.00001);

	if (rcoor2.X != 0 && MM2 != 0 && KK2 != 0)
	{
		sate_num.KK2 = KK2;
		sate_num.MM2 = MM2;
		sate_num.ALL_GB2 = ALL_GB2;
		sate_num.delX2 = rcoor2.X;
		sate_num.delY2 = rcoor2.Y;
		sate_num.delZ2 = rcoor2.Z;
		sate_num.M2_P1 = rcoor2.P1;
		sate_num.M2_P2 = rcoor2.P2;
		sate_num.GDOP2 = GDOP2;
		sate_num.PDOP2 = PDOP2;
	}

}
void CNDGNSS::MOVING_POS_MODULE4_RAIM(double  xyz2ldz6[],BS_PR_CR BBPC[], DATG dg0[], GEPH geph[MAXPRN_NUM], rp &rcoor2, Sate_NUM &sate_num,int Bn[],int Bp[])
{
	double	delt = 1;								//do...while()限制条件中的接收机X坐标迭代控制条件
	double	GDOP2 = 0, PDOP2 = 0;
	DATG dg[5] = { 0 };
	//int i = 0;
	dg[1] = dg0[0];
	BS_PR_CR BPC={0};
	int M1gps_num = 0, M1bds_num = 0, M1glo_num = 0;	//<流动站1/2>GPS可见卫星数

	for (int ii = 0; ii<dg[1].nsat; ii++)
	{
		if (dg[1].prn[ii] <= 33)
			M1gps_num++;
		if (dg[1].prn[ii] >= 38 && dg[1].prn[ii] <= 61)
			M1glo_num++;
		if (dg[1].prn[ii] >= 161 && dg[1].prn[ii] <= 197)
			M1bds_num++;
	}


	double	C1X, C1Y, C1Z;							//网格点1坐标
	double	C2X, C2Y, C2Z;							//网格点2坐标
	double	C3X, C3Y, C3Z;							//网格点3坐标
	double	C4X, C4Y, C4Z;							//网格点4坐标
	double MX, MY, MZ;                              //流动站坐标
	double C1_M, C2_M, C3_M, C4_M;                  //流动站与中心点间距离
	double s1, s2, s3, s4, s;
	double a[5]={0};
	//----------------------------------------------------------------------------------------------------------
	//这里因为是车载，所以流动站一直在变，那么如果流动站有坐标，就用流动站坐标到各基准站的距离，如果流动站坐标为0，就用监测站坐标，一般流动站第一次坐标为0，以后都会有值，为上一次的解得的值;
	IOFH ih3[4] = { 0 };
	//01MNZU
	//02MNYG
	//03ANYE



	double stationXYZ[4*3] =
	{
		-1360033.9403,5292219.8261,3279833.6918,
		-1460122.5642,5326238.9128,3180485.8097,
		-1385477.5551,5382919.3157,3118352.9324,
		-1386985.5690,5292102.2012,3268565.3229 



		/*-1337148.6337, 5287223.7322, 3297228.9847,
		-1460122.5642, 5326238.9128, 3180485.8097,
		-1386985.5690, 5292102.2012, 3268565.3229,
		-1385477.5551, 5382919.3157, 3118352.9324*/
	};

	for (int i = 0; i<4; i++)
	{
		ih3[i].ntype = 5;
		CString strObs_type = _T("C1 L1 P2 L2 B3");
		memcpy(ih3[i].type, strObs_type, strObs_type.GetLength() + 1);
		ih3[i].xyz[0] = stationXYZ[3*i+0];
		ih3[i].xyz[1] = stationXYZ[3*i+1];
		ih3[i].xyz[2] = stationXYZ[3*i+2];

	}

	MX = xyz2ldz6[0];
	MY = xyz2ldz6[1];
	MZ = xyz2ldz6[2];

	C1X = ih3[0].xyz[0];
	C1Y = ih3[0].xyz[1];
	C1Z = ih3[0].xyz[2];
	C2X = ih3[1].xyz[0];
	C2Y = ih3[1].xyz[1];
	C2Z = ih3[1].xyz[2];
	C3X = ih3[2].xyz[0];
	C3Y = ih3[2].xyz[1];
	C3Z = ih3[2].xyz[2];
	C4X = ih3[3].xyz[0];
	C4Y = ih3[3].xyz[1];
	C4Z = ih3[3].xyz[2];

	C1_M = sqrt(pow(C1X - MX, 2) + pow(C1Y - MY, 2) + pow(C1Z - MZ, 2));
	C2_M = sqrt(pow(C2X - MX, 2) + pow(C2Y - MY, 2) + pow(C2Z - MZ, 2));
	C3_M = sqrt(pow(C3X - MX, 2) + pow(C3Y - MY, 2) + pow(C3Z - MZ, 2));
	C4_M = sqrt(pow(C4X - MX, 2) + pow(C4Y - MY, 2) + pow(C4Z - MZ, 2));

	s1 = 1.0 / C1_M; s2 = 1.0 / C2_M; s3 = 1.0 / C3_M; s4 = 1.0 / C4_M;
	s = s1 + s2 + s3 + s4;
	a[1] = s1 / s; a[2] = s2 / s; a[3] = s3 / s; a[4] = s4 / s;
	//------------------------------------------------------------------------------------------------------------
	//------------------------------------------------------------------------------------------------------------



	int k[10]={0}, nn1 = 0, pp = 0;
	for ( k[1] = 0; k[1]<Bn[1]; k[1]++)						//主控站1GPS卫星数
	{
		for ( k[2] = 0; k[2]<Bn[2]; k[2]++)					//监测站2GPS卫星数
		{
			if (BBPC[1].G_PRN[k[1]] == BBPC[2].G_PRN[k[2]])
			{
				for ( k[3] = 0; k[3]<Bn[3]; k[3]++)			//监测站3GPS卫星数
				{
					if (BBPC[1].G_PRN[k[1]] == BBPC[3].G_PRN[k[3]])
					{
						for ( k[4] = 0; k[4]<Bn[4]; k[4]++)					//监测站4GPS卫星数
						{
							if (BBPC[1].G_PRN[k[1]] == BBPC[4].G_PRN[k[4]])
							{
								//for ( k[5] = 0; k[5]<Bn[5]; k[5]++)			//监测站5GPS卫星数
								//{
								//	if (BBPC[1].G_PRN[k[1]] == BBPC[5].G_PRN[k[5]])
								//	{
								//		for ( k[6] = 0; k[6]<Bn[6]; k[6]++)			//监测站6GPS卫星数
								//		{
								//			if (BBPC[1].G_PRN[k[1]] == BBPC[6].G_PRN[k[6]])
								//			{
								BPC.G_PRN[nn1] = BBPC[1].G_PRN[k[1]];//反距离加权后的BPC除伪距改正项外，其他与主控站一致;
								for(int njjzz=1;njjzz< 5;njjzz++){BPC.GPC[nn1] += a[njjzz]*BBPC[njjzz].GPC[k[njjzz]];}//NO_JZZ个基准站

								nn1++;
								break;
								//			}
								//		}
								//		break;
								//	}
								//}
								//break;
							}
						}
						break;
					}
				}
				break;
			}
		}
	}
	for ( k[1] = 0; k[1]<Bp[1]; k[1]++)						//主控站1BDS卫星数
	{
		for ( k[2] = 0; k[2]<Bp[2]; k[2]++)					//监测站2BDS卫星数
		{
			if (BBPC[1].C_PRN[k[1]] == BBPC[2].C_PRN[k[2]])
			{
				for ( k[3] = 0; k[3]<Bp[3]; k[3]++)			//监测站3BDS卫星数
				{
					if (BBPC[1].C_PRN[k[1]] == BBPC[3].C_PRN[k[3]])
					{
						for ( k[4] = 0; k[4]<Bp[4]; k[4]++)					//监测站4BDS卫星数
						{
							if (BBPC[1].C_PRN[k[1]] == BBPC[4].C_PRN[k[4]])
							{
								//for ( k[5] = 0; k[5]<Bp[5]; k[5]++)			//监测站5BDS卫星数
								//{
								//	if (BBPC[1].C_PRN[k[1]] == BBPC[5].C_PRN[k[5]])
								//	{
								//		for ( k[6] = 0; k[6]<Bp[6]; k[6]++)			//监测站6BDS卫星数
								//		{
								//			if (BBPC[1].C_PRN[k[1]] == BBPC[6].C_PRN[k[6]])
								//			{
								BPC.C_PRN[pp] = BBPC[1].C_PRN[k[1]];//反距离加权后的BPC除伪距改正项外，其他与主控站一致;
								for(int njjzz=1;njjzz< 5;njjzz++){BPC.CPC[pp] += a[njjzz]*BBPC[njjzz].CPC[k[njjzz]];}

								pp++;
								break;
								//			}
								//		}
								//		break;
								//	}
								//}
								//break;
							}
						}
						break;
					}
				}
				break;
			}
		}
	}




	/************▼流动站1  dg[1]计算▼↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/

	double	M2X0, M2Y0, M2Z0;							//流动站初始坐标;
	double	M2g_swj, M2g_R, M2b_swj, M2b_R;
	double	M2G_XK, M2G_YK, M2G_ZK, M2B_XK, M2B_YK, M2B_ZK;	//初始坐标;
	int		MM2, KK2, ALL_GB2;
	double	M2gps_wj[32] = { 0 }, M2GPS_SR[32] = { 0 };	//流动站解算的gps伪距&近似距离——存储值;
	double	M2bds_wj[35] = { 0 }, M2BDS_SR[35] = { 0 };	//流动站解算的bds伪距&近似距离——存储值;
	int		M2GPRN[32] = { 0 };						//流动站gpsPRN号——存储值;
	int		M2BPRN[35] = { 0 };						//流动站bdsPRN号——存储值;
	sp		M2gps_coor = { 0 }, M2bds_coor = { 0 };		//流动站解算的gps与bds的卫星坐标——存储值;

	double	M2_gps_wj[32] = { 0 }, M2_GPS_SR[32] = { 0 };//流动站最终解算;
	double	M2_bds_wj[35] = { 0 }, M2_BDS_SR[35] = { 0 };//流动站最终解算;
	int		M2_GPRN[32] = { 0 };					//流动站最终解算;
	int		M2_BPRN[35] = { 0 };					//流动站最终解算;
	sp		M2_gps_coor = { 0 }, M2_bds_coor = { 0 };	//流动站最终解算;


	double check2_gps[32] = { 0 }, check2_bds[35] = { 0 };//检测伪距改正输出;
	//int	m2 = 0, k2 = 0;								//循环回代置零;
	//rp		rcoor2={0};
	rcoor2.X = xyz2ldz6[0];
	rcoor2.Y = xyz2ldz6[1];
	rcoor2.Z = xyz2ldz6[2];


	int xunhuan=0;
	do		//最多循环10次跳出，代替do。。。。while
	{ 


		if( xunhuan>14)	{break;}		//最多循环10次跳出，代替do。。。。while
		xunhuan++;
		//for (int xunhuan = 0; xunhuan<15; xunhuan++)			//最多循环10次跳出，代替do。。。。while
		//{
		//double	M2gps_wj[32] = { 0 }, M2GPS_SR[32] = { 0 };	//流动站解算的gps伪距&近似距离——存储值;
		//double	M2bds_wj[35] = { 0 }, M2BDS_SR[35] = { 0 };	//流动站解算的bds伪距&近似距离——存储值;
		//int		M2GPRN[32] = { 0 };						//流动站gpsPRN号——存储值;
		//int		M2BPRN[35] = { 0 };						//流动站bdsPRN号——存储值;
		//sp		M2gps_coor = { 0 }, M2bds_coor = { 0 };		//流动站解算的gps与bds的卫星坐标——存储值;

		//double	M2_gps_wj[32] = { 0 }, M2_GPS_SR[32] = { 0 };//流动站最终解算;
		//double	M2_bds_wj[35] = { 0 }, M2_BDS_SR[35] = { 0 };//流动站最终解算;
		//int		M2_GPRN[32] = { 0 };					//流动站最终解算;
		//int		M2_BPRN[35] = { 0 };					//流动站最终解算;
		//sp		M2_gps_coor = { 0 }, M2_bds_coor = { 0 };	//流动站最终解算;


		//double check2_gps[32] = { 0 }, check2_bds[35] = { 0 };//检测伪距改正输出;
		int	m2 = 0, k2 = 0;								//循环回代置零;
		M2X0 = rcoor2.X;								//用于循环回代;
		M2Y0 = rcoor2.Y;
		M2Z0 = rcoor2.Z;

		for (int ii = 0; ii<M1gps_num; ii++)				//基于流动站计算卫星位置及伪距&卫地距;
		{
			M2g_swj = 0, M2g_R = 0;
			M2G_XK = 0, M2G_YK = 0, M2G_ZK = 0;
			GNSS_POS_MODULE(geph, dg, 1, M2X0, M2Y0, M2Z0, &M2g_swj, &M2g_R, &M2G_XK, &M2G_YK, &M2G_ZK, ii, 1);//dg后面的参数为站号,为了配合dg【】中的号;
			if (M2g_swj != 0 && M2g_R != 0)
			{
				M2gps_wj[m2] = M2g_swj;
				M2GPS_SR[m2] = M2g_R;
				M2GPRN[m2] = dg[1].prn[ii];
				M2gps_coor.X[m2] = M2G_XK;
				M2gps_coor.Y[m2] = M2G_YK;
				M2gps_coor.Z[m2] = M2G_ZK;

				check2_gps[m2] = M2g_R - M2g_swj;					//检测改正值正确与否,与BDS的改正值对比,注意：检测时要加入卫星钟差，以使对比与BDS的改正值是否一致,正确的应该和BDS是一致的;
				m2++;											//m为可利用GPS卫星数目
			}
		}
		for (int ii = M1gps_num + M1glo_num; ii<dg[1].nsat; ii++)		//基于流动站计算卫星位置及伪距&卫地距;
		{
			M2b_swj = 0, M2b_R = 0;
			M2B_XK = 0, M2B_YK = 0, M2B_ZK = 0;
			GNSS_POS_MODULE(geph, dg, 1, M2X0, M2Y0, M2Z0, &M2b_swj, &M2b_R, &M2B_XK, &M2B_YK, &M2B_ZK, ii, 2);//dg后面的参数为站号,为了配合dg【】中的号;
			if (M2b_swj != 0 && M2b_R != 0)
			{
				M2bds_wj[k2] = M2b_swj;
				M2BDS_SR[k2] = M2b_R;
				M2BPRN[k2] = dg[1].prn[ii];
				M2bds_coor.X[k2] = M2B_XK;
				M2bds_coor.Y[k2] = M2B_YK;
				M2bds_coor.Z[k2] = M2B_ZK;

				check2_bds[k2] = M2b_R - M2b_swj;			//检测改正值正确与否,与GPS的改正值对比,注意：检测时要加入卫星钟差，以使对比与GPS的改正值是否一致,正确的应该和GPS是一致的;
				k2++;								//m为可利用GPS卫星数目
			}
		}

		/********▼匹配伪距改正数▼********/;
		int mm2 = 0, kk2 = 0;							//该历元中流动站和改正数相匹配的数;
		for (int ii = 0; ii<m2; ii++)				//匹配从3个基准站传过来的通过反距离加权后的GPS伪距改正值;
		{
			for (int jj = 0; jj<nn1; jj++)
			{
				//if (M2GPRN[ii]==BPC.G_PRN[jj]&&BPC.C_PRN[jj]!=bad_BPRN[0]&&BPC.C_PRN[jj]!=bad_BPRN[1]&&BPC.C_PRN[jj]!=bad_BPRN[2]&&BPC.C_PRN[jj]!=bad_BPRN[3]&&BPC.C_PRN[jj]!=bad_BPRN[4])
				if (M2GPRN[ii] == BPC.G_PRN[jj])
				{
					M2_gps_wj[mm2] = M2gps_wj[ii] + BPC.GPC[jj];
					M2_GPS_SR[mm2] = M2GPS_SR[ii];
					M2_GPRN[mm2] = M2GPRN[ii];
					M2_gps_coor.X[mm2] = M2gps_coor.X[ii];
					M2_gps_coor.Y[mm2] = M2gps_coor.Y[ii];
					M2_gps_coor.Z[mm2] = M2gps_coor.Z[ii];
					mm2++;
					break;
				}
			}
		}
		for (int ii = 0; ii<k2; ii++)				//匹配从3个基准站传过来的的通过反距离加权后的BDS伪距改正值;
		{
			for (int jj = 0; jj<pp; jj++)
			{
				//if (M2BPRN[ii]==BPC.C_PRN[jj]&&BPC.C_PRN[jj]!=bad_BPRN[0]&&BPC.C_PRN[jj]!=bad_BPRN[1]&&BPC.C_PRN[jj]!=bad_BPRN[2]&&BPC.C_PRN[jj]!=bad_BPRN[3]&&BPC.C_PRN[jj]!=bad_BPRN[4])
				if (M2BPRN[ii] == BPC.C_PRN[jj])
				{
					M2_bds_wj[kk2] = M2bds_wj[ii] + BPC.CPC[jj];
					M2_BDS_SR[kk2] = M2BDS_SR[ii];
					M2_BPRN[kk2] = M2BPRN[ii];
					M2_bds_coor.X[kk2] = M2bds_coor.X[ii];
					M2_bds_coor.Y[kk2] = M2bds_coor.Y[ii];
					M2_bds_coor.Z[kk2] = M2bds_coor.Z[ii];
					kk2++;
					break;
				}
			}
		}

		/************▼定位解算▼↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
		MM2 = mm2, KK2 = kk2;
		ALL_GB2 = MM2 + KK2;
		if (ALL_GB2 >= 5 && MM2>2 && KK2>2)
		{
			recei_coor(&rcoor2, M2_gps_coor, M2_gps_wj, M2_GPS_SR, M2_bds_coor, M2_bds_wj, M2_BDS_SR, ALL_GB2, MM2, KK2, &GDOP2, &PDOP2, dg[1].tg.second);//计算接收机坐标,返回位置的改正数rcoor.X、rcoor.Y、rcoor.Z;
			if (rcoor2.X != 0 && rcoor2.Y != 0 && rcoor2.Z != 0)
			{
				rcoor2.X = rcoor2.X + M2X0;			//新的接收机坐标=改正数+初值，下面判断，如果delt>0.001的话，返回do，将rcoor.X重新作为初值，循环计算到delt<0.001;
				rcoor2.Y = rcoor2.Y + M2Y0;
				rcoor2.Z = rcoor2.Z + M2Z0;
				//delt = rcoor2.X - M2X0;
				delt = sqrt(pow(rcoor2.X - M2X0,2.0)+pow(rcoor2.Y - M2Y0,2.0)+pow(rcoor2.Z - M2Z0,2.0));

				if (fabs(delt)<0.00001)
					break;
			}
			else
			{
				rcoor2.X = 0;
				rcoor2.Y = 0;
				rcoor2.Z = 0;
				rcoor2.P1 = 0;
				rcoor2.P2 = 0;
				break;
			}
		}
		else
		{
			rcoor2.X = 0;
			rcoor2.Y = 0;
			rcoor2.Z = 0;
			rcoor2.P1 = 0;
			rcoor2.P2 = 0;
			break;
		}
		//if (rcoor2.X!=0&&fabs(delt)<0.00001)
		//	break;
	}while(delt>0.00001);
	rp rcoor_raim=rcoor2;
	int MM_raim=MM2,KK_raim=KK2;
	double GDOP_raim=0.0,PDOP_raim=0.0;
	int chaoxian_num = 0;						//监测站监测卫星，监测有几个超限卫星chaoxian_num;
	int bad_GPRN[20] = { 0 }, bad_BPRN[20] = { 0 };	//存储坏的GPS卫星和坏的BDS卫星;
	int B_bad_num = 0, G_bad_num = 0;								//BDS、GPS残差超限的个数;
	int T = MM_raim + KK_raim;						//多系统定位总的卫星个数Totle;
	int i, j;									//为了进行循环;
	int final_N, final_P;
	double X_raim0, Y_raim0, Z_raim0;
	X_raim0 = rcoor_raim.X;
	Y_raim0 = rcoor_raim.Y;
	Z_raim0 = rcoor_raim.Z;

	//double xyztch[3]={0};//剔除后坐标xyz0
	//double NEUtch[3]={0};//
	////int index;//是否循环计算的标志,也即是是否有粗差的标志;
	//double a=0,b=0,c=0;
	/*
	if(chaoxian_num>10)
	{
	memset(Bn,0x00,sizeof(int)*20);
	memset(Bp,0x00,sizeof(int)*20);
	memset(BBPC,0x00,sizeof(BS_PR_CR)*20);	
	break;
	}*/
	//index = 0;
	double	*ll = new	double[T]();		//课本P57参数  等加以double	(*ll)[1]=	 new	double[T][1];
	double	*mm = new	double[T]();
	double	*nn = new	double[T]();
	double	*L = new	double[T]();
	double	*A = new	double[T * 5]();		//状态矩阵A;
	double	*AT = new	double[5 * T]();		//状态矩阵A的转置;
	double	*P = new	double[T*T]();		//权矩阵P;              ()是对动态内存进行初始化
	double	*ATP = new	double[5 * T]();		//A的转置乘以P;
	double	*ATPA = new	double[5 * 5]();		//A的转置乘以P乘以A;
	double	*inv_ATPA = new	double[5 * 5]();		//(A的转置乘以P乘以A)的逆;
	double	*ATPL = new	double[5]();		//A的转置乘以P乘以L;
	double	*result = new	double[5]();		//(A的转置乘以P乘以A)乘以(A的转置乘以P乘以L)，(inv_ATPA)(ATPL);


	double	*AX = new	double[T]();		//A乘以X;
	double  *V = new	double[T]();		//V=AX-L
	double	*VT = new	double[1 * T]();
	double	*VTP = new	double[1 * T]();
	double	*VTPV = new	double[T * 1]();

	///////////////////////////////////////////列法方程;

	//cout<<"系数矩阵B和L"<<endl;																	//
	for (i = 0; i<MM_raim; i++)
	{
		ll[i] = (M2_gps_coor.X[i] - rcoor_raim.X) / M2_GPS_SR[i];
		mm[i] = (M2_gps_coor.Y[i] - rcoor_raim.Y) / M2_GPS_SR[i];
		nn[i] = (M2_gps_coor.Z[i] - rcoor_raim.Z) / M2_GPS_SR[i];
		A[i * 5 + 0] = ll[i];
		A[i * 5 + 1] = mm[i];
		A[i * 5 + 2] = nn[i];
		A[i * 5 + 3] = -1;
		//A[i*5+4]=0;								//初始化了就不需要了
		L[i] = M2_GPS_SR[i] - M2_gps_wj[i];

		//printf("%8.3f%8.3f%8.3f%8.3f%8.3f%16.3f\n",A[i*5+0],A[i*5+1],A[i*5+2],A[i*5+3],A[i*5+4],L[i]);	//

		P[i*T + i] = 1;									//给GPS定的权
	}
	for (j = MM_raim; j<T; j++)
	{
		ll[j] = (M2_bds_coor.X[j - MM_raim] - rcoor_raim.X) / M2_BDS_SR[j - MM_raim];
		mm[j] = (M2_bds_coor.Y[j - MM_raim] - rcoor_raim.Y) / M2_BDS_SR[j - MM_raim];
		nn[j] = (M2_bds_coor.Z[j - MM_raim] - rcoor_raim.Z) / M2_BDS_SR[j - MM_raim];
		A[j * 5 + 0] = ll[j];
		A[j * 5 + 1] = mm[j];
		A[j * 5 + 2] = nn[j];
		//A[j*5+3]=0;								//初始化了就不需要了;
		A[j * 5 + 4] = -1;
		L[j] = M2_BDS_SR[j - MM_raim] - M2_bds_wj[j - MM_raim];

		//printf("%8.3f%8.3f%8.3f%8.3f%8.3f%16.3f\n",A[j*5+0],A[j*5+1],A[j*5+2],A[j*5+3],A[j*5+4],L[j]);	//

		P[j*T + j] = 1;									//给BDS定的权
	}

	///////////////////////////////////////////通过函数的指针进行矩阵的运算，传出需要的矩阵;
	M_Tra(T, 5, A, AT);							//矩阵转置	A的转置		传出AT;
	M_Mul(5, T, T, AT, P, ATP);						//矩阵相乘	AT乘P		传出ATP;
	M_Mul(5, T, 5, ATP, A, ATPA);					//			ATP乘A		传出ATPA;
	M_Inv(5, ATPA, inv_ATPA);						//矩阵求逆	ATPA的逆		传出inv_ATPA;
	M_Mul(5, T, 1, ATP, L, ATPL);					//			ATP乘L		传出ATPL;
	M_Mul(5, 5, 1, inv_ATPA, ATPL, result);			//			inv_ATPA乘ATPL传出result;

	//cout<<inv_ATPA[1]<<inv_ATPA[2]<<inv_ATPA[3]<<inv_ATPA[4]<<inv_ATPA[5]<<endl;
	//cout<<ATPL[1]<<ATPL[2]<<ATPL[3]<<ATPL[4]<<ATPL[5]<<endl;
	if (inv_ATPA != NULL)
	{
		rcoor_raim.X = result[0];
		rcoor_raim.Y = result[1];
		rcoor_raim.Z = result[2];
		rcoor_raim.P1 = result[3];
		rcoor_raim.P2 = result[4];

		for (i = 0; i<5; i++)
			GDOP_raim += inv_ATPA[i * 5 + i];
		sate_num.GDOP_raim = sqrt(GDOP_raim);
		for (i = 0; i<3; i++)
			PDOP_raim += inv_ATPA[i * 5 + i];
		sate_num.PDOP_raim = sqrt(PDOP_raim);
	}
	else
	{
		rcoor_raim.X = 0;
		rcoor_raim.Y = 0;
		rcoor_raim.Z = 0;
		rcoor_raim.P1 = 0;
		rcoor_raim.P2 = 0;
		//printf("这个历元数据无法求解!\n");
		//system("pause");
	}

	double X[5][1];
	X[0][0] = rcoor_raim.X;
	X[0][1] = rcoor_raim.Y;
	X[0][2] = rcoor_raim.Z;
	X[0][3] = rcoor_raim.P1;
	X[0][4] = rcoor_raim.P2;
	//double	*AX=	new	double[T]();			//A乘以X;
	M_Mul(T, 5, 1, A, X[0], AX);							//矩阵相乘;
	//double  *V=		new	double[T]();			//V=AX-L

	for (int p = 0; p<T; p++)
	{
		V[p] = AX[p] - L[p];
	}
	//double *VT=		new	double[1*T]();
	//double *VTP=	new	double[1*T]();
	//double *VTPV=	new	double[T*1]();

	M_Tra(T, 1, V, VT);								//矩阵转置	A的转置		传出AT;
	M_Mul(1, T, T, VT, P, VTP);							//矩阵相乘	AT乘P		传出ATP;
	M_Mul(1, T, 1, VTP, V, VTPV);
	double RMS_raim = sqrt(*VTPV / (T - 5));
	double w[32];
	for (i = 0; i<T; i++)
	{
		w[i] = fabs(V[i]) / (RMS_raim*sqrt((T - 1.0) / T));
		//printf("%16.8f\n",w[i]);				//
	}
	int n_s=0;
	int NNN,PPP;

	for(i=0;i<T;i++)
	{
		if(w[i]> 3)
		{
			//w1=w[i];
			n_s=i;
			NNN = MM_raim;
			PPP = KK_raim;
			if (n_s>NNN - 1)			//说明是BDS卫星的
			{
				bad_BPRN[chaoxian_num] = M2_BPRN[n_s - NNN];//如果GPS7颗，BDS9颗，现在pp=8，也就是w中第9个，那么就是BDS卫星的第2个对应于1，即8-7=1;
				//chaoxian_num++;
				for(int j=1;j<5;j++)//四个基准站，依次消除坏星
				{
					for (int m=0;m<Bp[j];m++)//从0开始依次比对prn
					{
						if (bad_BPRN[chaoxian_num]==BBPC[j].C_PRN[m])//当prn相同时就消除这颗卫星对应的内容
						{
							for (int s = m; s<Bp[j]; s++)//从坏星开始将后一个星内容覆盖前一个卫星内容
							{
								BBPC[j].C_PRN[s]=BBPC[j].C_PRN[s+1];
								BBPC[j].CPC[s]=BBPC[j].CPC[s+1];
							}
							Bp[j]--;
							break;
						}
					}
				}
				B_bad_num++;
				KK_raim = PPP - 1;		//新的BDS卫星个数
				chaoxian_num++;
			}
			else					//说明是GPS卫星的
			{
				bad_GPRN[chaoxian_num] = M2_GPRN[n_s];
				for(int j=1;j<5;j++)//四个基准站，依次消除坏星
				{
					for (int m=0;m<Bn[j];m++)//从0开始依次比对prn
					{
						if (bad_GPRN[chaoxian_num]==BBPC[j].G_PRN[m])//当prn相同时就消除这颗卫星对应的内容
						{
							for (int s = m; s<Bn[j]; s++)//从坏星开始将后一个星内容覆盖前一个卫星内容
							{
								BBPC[j].G_PRN[s]=BBPC[j].G_PRN[s+1];
								BBPC[j].GPC[s]=BBPC[j].GPC[s+1];
							}
							Bn[j]--;
							break;
						}
					}
				}
				G_bad_num++;
				MM_raim = NNN - 1;		//新的GPS卫星个数
				chaoxian_num++;
			}
		}
	}				
	MOVING_POS_MODULE4(xyz2ldz6,BBPC, dg0, geph, rcoor2, sate_num,Bn, Bp);

	if (rcoor2.X != 0 && MM2 != 0 && KK2 != 0)
	{
		sate_num.KK2 = KK2;
		sate_num.MM2 = MM2;
		sate_num.ALL_GB2 = ALL_GB2;
		sate_num.delX2 = rcoor2.X;
		sate_num.delY2 = rcoor2.Y;
		sate_num.delZ2 = rcoor2.Z;
		sate_num.M2_P1 = rcoor2.P1;
		sate_num.M2_P2 = rcoor2.P2;
		sate_num.GDOP2 = GDOP2;
		sate_num.PDOP2 = PDOP2;
	}

}


void CNDGNSS::MONITOR_POS_MODULE_RAIM(IOFH m_iofh[],BS_PR_CR BBPC[], DATG dg0[], GEPH geph[MAXPRN_NUM],  Sate_NUM &sate_num,int Bn[],int Bp[])
{
	double	delt = 1;								//do...while()限制条件中的接收机X坐标迭代控制条件
	double	GDOP2 = 0, PDOP2 = 0;
	DATG dg[5] = { 0 };
	int i = 0;
	dg[i + 1] = dg0[0];
	BS_PR_CR BPC={0};
	int M1gps_num = 0, M1bds_num = 0, M1glo_num = 0;	//<流动站1/2>GPS可见卫星数
	rp rcoor2;

	for (int ii = 0; ii<dg[1].nsat; ii++)
	{
		if (dg[1].prn[ii] <= 33)
			M1gps_num++;
		if (dg[1].prn[ii] >= 38 && dg[1].prn[ii] <= 61)
			M1glo_num++;
		if (dg[1].prn[ii] >= 161 && dg[1].prn[ii] <= 197)
			M1bds_num++;
	}


	double	C1X, C1Y, C1Z;							//网格点1坐标
	double	C2X, C2Y, C2Z;							//网格点2坐标
	double	C3X, C3Y, C3Z;							//网格点3坐标
	double	C4X, C4Y, C4Z;							//网格点4坐标
	double MX, MY, MZ;                              //流动站坐标
	double C1_M, C2_M, C3_M, C4_M;                  //流动站与中心点间距离
	double s1, s2, s3, s4, s;
	double a[5]={0};
	//----------------------------------------------------------------------------------------------------------
	//这里因为是车载，所以流动站一直在变，那么如果流动站有坐标，就用流动站坐标到各基准站的距离，如果流动站坐标为0，就用监测站坐标，一般流动站第一次坐标为0，以后都会有值，为上一次的解得的值;
	IOFH ih3[4] = { 0 };

	for(int iii=0;iii<4;iii++)
	{
		ih3[i].xyz[0] = m_iofh[i].xyz[0];
		ih3[i].xyz[1] = m_iofh[i].xyz[1];
		ih3[i].xyz[2] = m_iofh[i].xyz[2];
	}

	MX = m_iofh[4].xyz[0];
	MY = m_iofh[4].xyz[0];
	MZ = m_iofh[4].xyz[0];

	C1X = ih3[0].xyz[0];
	C1Y = ih3[0].xyz[1];
	C1Z = ih3[0].xyz[2];
	C2X = ih3[1].xyz[0];
	C2Y = ih3[1].xyz[1];
	C2Z = ih3[1].xyz[2];
	C3X = ih3[2].xyz[0];
	C3Y = ih3[2].xyz[1];
	C3Z = ih3[2].xyz[2];
	C4X = ih3[3].xyz[0];
	C4Y = ih3[3].xyz[1];
	C4Z = ih3[3].xyz[2];

	C1_M = sqrt(pow(C1X - MX, 2) + pow(C1Y - MY, 2) + pow(C1Z - MZ, 2));
	C2_M = sqrt(pow(C2X - MX, 2) + pow(C2Y - MY, 2) + pow(C2Z - MZ, 2));
	C3_M = sqrt(pow(C3X - MX, 2) + pow(C3Y - MY, 2) + pow(C3Z - MZ, 2));
	C4_M = sqrt(pow(C4X - MX, 2) + pow(C4Y - MY, 2) + pow(C4Z - MZ, 2));

	s1 = 1.0 / C1_M; s2 = 1.0 / C2_M; s3 = 1.0 / C3_M; s4 = 1.0 / C4_M;
	s = s1 + s2 + s3 + s4;
	a[1] = s1 / s; a[2] = s2 / s; a[3] = s3 / s; a[4] = s4 / s;
	//------------------------------------------------------------------------------------------------------------
	//------------------------------------------------------------------------------------------------------------



	int k[10]={0}, nn = 0, pp = 0;
	for ( k[1] = 0; k[1]<Bn[1]; k[1]++)						//主控站1GPS卫星数
	{
		for ( k[2] = 0; k[2]<Bn[2]; k[2]++)					//监测站2GPS卫星数
		{
			if (BBPC[1].G_PRN[k[1]] == BBPC[2].G_PRN[k[2]])
			{
				for ( k[3] = 0; k[3]<Bn[3]; k[3]++)			//监测站3GPS卫星数
				{
					if (BBPC[1].G_PRN[k[1]] == BBPC[3].G_PRN[k[3]])
					{
						for ( k[4] = 0; k[4]<Bn[4]; k[4]++)					//监测站4GPS卫星数
						{
							if (BBPC[1].G_PRN[k[1]] == BBPC[4].G_PRN[k[4]])
							{
								//for ( k[5] = 0; k[5]<Bn[5]; k[5]++)			//监测站5GPS卫星数
								//{
								//	if (BBPC[1].G_PRN[k[1]] == BBPC[5].G_PRN[k[5]])
								//	{
								//		for ( k[6] = 0; k[6]<Bn[6]; k[6]++)			//监测站6GPS卫星数
								//		{
								//			if (BBPC[1].G_PRN[k[1]] == BBPC[6].G_PRN[k[6]])
								//			{
								BPC.G_PRN[nn] = BBPC[1].G_PRN[k[1]];//反距离加权后的BPC除伪距改正项外，其他与主控站一致;
								for(int njjzz=1;njjzz< 5;njjzz++){BPC.GPC[nn] += a[njjzz]*BBPC[njjzz].GPC[k[njjzz]];}//NO_JZZ个基准站

								nn++;
								break;
								//			}
								//		}
								//		break;
								//	}
								//}
								//break;
							}
						}
						break;
					}
				}
				break;
			}
		}
	}
	for ( k[1] = 0; k[1]<Bp[1]; k[1]++)						//主控站1BDS卫星数
	{
		for ( k[2] = 0; k[2]<Bp[2]; k[2]++)					//监测站2BDS卫星数
		{
			if (BBPC[1].C_PRN[k[1]] == BBPC[2].C_PRN[k[2]])
			{
				for ( k[3] = 0; k[3]<Bp[3]; k[3]++)			//监测站3BDS卫星数
				{
					if (BBPC[1].C_PRN[k[1]] == BBPC[3].C_PRN[k[3]])
					{
						for ( k[4] = 0; k[4]<Bp[4]; k[4]++)					//监测站4BDS卫星数
						{
							if (BBPC[1].C_PRN[k[1]] == BBPC[4].C_PRN[k[4]])
							{
								//for ( k[5] = 0; k[5]<Bp[5]; k[5]++)			//监测站5BDS卫星数
								//{
								//	if (BBPC[1].C_PRN[k[1]] == BBPC[5].C_PRN[k[5]])
								//	{
								//		for ( k[6] = 0; k[6]<Bp[6]; k[6]++)			//监测站6BDS卫星数
								//		{
								//			if (BBPC[1].C_PRN[k[1]] == BBPC[6].C_PRN[k[6]])
								//			{
								BPC.C_PRN[pp] = BBPC[1].C_PRN[k[1]];//反距离加权后的BPC除伪距改正项外，其他与主控站一致;
								for(int njjzz=1;njjzz< 5;njjzz++){BPC.CPC[pp] += a[njjzz]*BBPC[njjzz].CPC[k[njjzz]];}

								pp++;
								break;
								//			}
								//		}
								//		break;
								//	}
								//}
								//break;
							}
						}
						break;
					}
				}
				break;
			}
		}
	}




	/************▼流动站1  dg[1]计算▼↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/

	double	M2X0, M2Y0, M2Z0;							//流动站初始坐标;
	double	M2g_swj, M2g_R, M2b_swj, M2b_R;
	double	M2G_XK, M2G_YK, M2G_ZK, M2B_XK, M2B_YK, M2B_ZK;	//初始坐标;
	int		MM2, KK2, ALL_GB2;
	//rp		rcoor2={0};
	double xyz2ldz6[3];
	xyz2ldz6[0]=m_iofh[4].xyz[0];
	xyz2ldz6[1]=m_iofh[4].xyz[1];
	xyz2ldz6[2]=m_iofh[4].xyz[2];

	rcoor2.X = xyz2ldz6[0];
	rcoor2.Y = xyz2ldz6[1];
	rcoor2.Z = xyz2ldz6[2];

	int chaoxian_num = 0;						//监测站监测卫星，监测有几个超限卫星chaoxian_num;
	int bad_GPRN[20] = { 0 }, bad_BPRN[20] = { 0 };	//存储坏的GPS卫星和坏的BDS卫星;



	double	M2gps_wj[32] = { 0 }, M2GPS_SR[32] = { 0 };	//流动站解算的gps伪距&近似距离——存储值;
	double	M2bds_wj[35] = { 0 }, M2BDS_SR[35] = { 0 };	//流动站解算的bds伪距&近似距离——存储值;
	int		M2GPRN[32] = { 0 };						//流动站gpsPRN号——存储值;
	int		M2BPRN[35] = { 0 };						//流动站bdsPRN号——存储值;
	sp		M2gps_coor = { 0 }, M2bds_coor = { 0 };		//流动站解算的gps与bds的卫星坐标——存储值;

	double	M2_gps_wj[32] = { 0 }, M2_GPS_SR[32] = { 0 };//流动站最终解算;
	double	M2_bds_wj[35] = { 0 }, M2_BDS_SR[35] = { 0 };//流动站最终解算;
	int		M2_GPRN[32] = { 0 };					//流动站最终解算;
	int		M2_BPRN[35] = { 0 };					//流动站最终解算;
	sp		M2_gps_coor = { 0 }, M2_bds_coor = { 0 };	//流动站最终解算;
	int xunhuan = 0;
	do		//最多循环10次跳出，代替do。。。。while
	{ 


		if( xunhuan>14)	{break;}		//最多循环10次跳出，代替do。。。。while
		xunhuan++;


		double check2_gps[32] = { 0 }, check2_bds[35] = { 0 };//检测伪距改正输出;
		int	m2 = 0, k2 = 0;								//循环回代置零;
		M2X0 = rcoor2.X;								//用于循环回代;
		M2Y0 = rcoor2.Y;
		M2Z0 = rcoor2.Z;

		for (int ii = 0; ii<M1gps_num; ii++)				//基于流动站计算卫星位置及伪距&卫地距;
		{
			M2g_swj = 0, M2g_R = 0;
			M2G_XK = 0, M2G_YK = 0, M2G_ZK = 0;
			GNSS_POS_MODULE(geph, dg, 1, M2X0, M2Y0, M2Z0, &M2g_swj, &M2g_R, &M2G_XK, &M2G_YK, &M2G_ZK, ii, 1);//dg后面的参数为站号,为了配合dg【】中的号;
			if (M2g_swj != 0 && M2g_R != 0)
			{
				M2gps_wj[m2] = M2g_swj;
				M2GPS_SR[m2] = M2g_R;
				M2GPRN[m2] = dg[1].prn[ii];
				M2gps_coor.X[m2] = M2G_XK;
				M2gps_coor.Y[m2] = M2G_YK;
				M2gps_coor.Z[m2] = M2G_ZK;

				check2_gps[m2] = M2g_R - M2g_swj;					//检测改正值正确与否,与BDS的改正值对比,注意：检测时要加入卫星钟差，以使对比与BDS的改正值是否一致,正确的应该和BDS是一致的;
				m2++;											//m为可利用GPS卫星数目
			}
		}
		for (int ii = M1gps_num + M1glo_num; ii<dg[1].nsat; ii++)		//基于流动站计算卫星位置及伪距&卫地距;
		{
			M2b_swj = 0, M2b_R = 0;
			M2B_XK = 0, M2B_YK = 0, M2B_ZK = 0;
			GNSS_POS_MODULE(geph, dg, 1, M2X0, M2Y0, M2Z0, &M2b_swj, &M2b_R, &M2B_XK, &M2B_YK, &M2B_ZK, ii, 2);//dg后面的参数为站号,为了配合dg【】中的号;
			if (M2b_swj != 0 && M2b_R != 0)
			{
				M2bds_wj[k2] = M2b_swj;
				M2BDS_SR[k2] = M2b_R;
				M2BPRN[k2] = dg[1].prn[ii];
				M2bds_coor.X[k2] = M2B_XK;
				M2bds_coor.Y[k2] = M2B_YK;
				M2bds_coor.Z[k2] = M2B_ZK;

				check2_bds[k2] = M2b_R - M2b_swj;			//检测改正值正确与否,与GPS的改正值对比,注意：检测时要加入卫星钟差，以使对比与GPS的改正值是否一致,正确的应该和GPS是一致的;
				k2++;								//m为可利用GPS卫星数目
			}
		}

		/********▼匹配伪距改正数▼********/;
		int mm2 = 0, kk2 = 0;							//该历元中流动站和改正数相匹配的数;
		for (int ii = 0; ii<m2; ii++)				//匹配从3个基准站传过来的通过反距离加权后的GPS伪距改正值;
		{
			for (int jj = 0; jj<nn; jj++)
			{
				//if (M2GPRN[ii]==BPC.G_PRN[jj]&&BPC.C_PRN[jj]!=bad_BPRN[0]&&BPC.C_PRN[jj]!=bad_BPRN[1]&&BPC.C_PRN[jj]!=bad_BPRN[2]&&BPC.C_PRN[jj]!=bad_BPRN[3]&&BPC.C_PRN[jj]!=bad_BPRN[4])
				if (M2GPRN[ii] == BPC.G_PRN[jj])
				{
					M2_gps_wj[mm2] = M2gps_wj[ii] + BPC.GPC[jj];
					M2_GPS_SR[mm2] = M2GPS_SR[ii];
					M2_GPRN[mm2] = M2GPRN[ii];
					M2_gps_coor.X[mm2] = M2gps_coor.X[ii];
					M2_gps_coor.Y[mm2] = M2gps_coor.Y[ii];
					M2_gps_coor.Z[mm2] = M2gps_coor.Z[ii];
					mm2++;
					break;
				}
			}
		}
		for (int ii = 0; ii<k2; ii++)				//匹配从3个基准站传过来的的通过反距离加权后的BDS伪距改正值;
		{
			for (int jj = 0; jj<pp; jj++)
			{
				//if (M2BPRN[ii]==BPC.C_PRN[jj]&&BPC.C_PRN[jj]!=bad_BPRN[0]&&BPC.C_PRN[jj]!=bad_BPRN[1]&&BPC.C_PRN[jj]!=bad_BPRN[2]&&BPC.C_PRN[jj]!=bad_BPRN[3]&&BPC.C_PRN[jj]!=bad_BPRN[4])
				if (M2BPRN[ii] == BPC.C_PRN[jj])
				{
					M2_bds_wj[kk2] = M2bds_wj[ii] + BPC.CPC[jj];
					M2_BDS_SR[kk2] = M2BDS_SR[ii];
					M2_BPRN[kk2] = M2BPRN[ii];
					M2_bds_coor.X[kk2] = M2bds_coor.X[ii];
					M2_bds_coor.Y[kk2] = M2bds_coor.Y[ii];
					M2_bds_coor.Z[kk2] = M2bds_coor.Z[ii];
					kk2++;
					break;
				}
			}
		}

		/************▼定位解算▼↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
		MM2 = mm2, KK2 = kk2;
		ALL_GB2 = MM2 + KK2;
		if (ALL_GB2 >= 5 && MM2>2 && KK2>2)
		{
			recei_coor(&rcoor2, M2_gps_coor, M2_gps_wj, M2_GPS_SR, M2_bds_coor, M2_bds_wj, M2_BDS_SR, ALL_GB2, MM2, KK2, &GDOP2, &PDOP2, dg[1].tg.second);//计算接收机坐标,返回位置的改正数rcoor.X、rcoor.Y、rcoor.Z;
			if (rcoor2.X != 0 && rcoor2.Y != 0 && rcoor2.Z != 0)
			{
				rcoor2.X = rcoor2.X + M2X0;			//新的接收机坐标=改正数+初值，下面判断，如果delt>0.001的话，返回do，将rcoor.X重新作为初值，循环计算到delt<0.001;
				rcoor2.Y = rcoor2.Y + M2Y0;
				rcoor2.Z = rcoor2.Z + M2Z0;
				delt = sqrt(pow(rcoor2.X - M2X0,2.0)+pow(rcoor2.Y - M2Y0,2.0)+pow(rcoor2.Z - M2Z0,2.0));
				//delt = rcoor2.X - M2X0;

			}
			else
			{
				rcoor2.X = 0;
				rcoor2.Y = 0;
				rcoor2.Z = 0;
				rcoor2.P1 = 0;
				rcoor2.P2 = 0;
				break;
			}
		}
		else
		{
			rcoor2.X = 0;
			rcoor2.Y = 0;
			rcoor2.Z = 0;
			rcoor2.P1 = 0;
			rcoor2.P2 = 0;
			break;
		}
		//if (rcoor2.X!=0&&fabs(delt)<0.00001)
		//	break;
	}while(delt>0.00001);



	double xyz[3]={0};//改正后坐标xyz0
	double NEU[3]={0};//,horizonD000wjcf=0
	xyz[0]=rcoor2.X;xyz[1]=rcoor2.Y;xyz[2]=rcoor2.Z;
	XYZ2NEU(m_iofh[4].xyz,xyz,NEU);//NEU4差分改正后xyz0相对于真值的NEU，用于评定精度
	//horizonD000wjcf=sqrt(NEU000wjcf[0]*NEU000wjcf[0]+NEU000wjcf[1]*NEU000wjcf[1]);//改正后水平偏差
	rp rcoor_raim=rcoor2;
	int MM_raim=MM2,KK_raim=KK2;
	double GDOP_raim=0.0,PDOP_raim=0.0;
	double aa,bb,cc;
	aa=fabs(NEU[0]);
	bb=fabs(NEU[1]);
	cc=fabs(NEU[2]);

	if(rcoor2.X!=0)
	{
		if(aa>2.0||bb>2.0||cc>4.0)//N,E,U限差224m，经过半天采集应设为112m
		{
			int B_bad_num = 0, G_bad_num = 0;								//BDS、GPS残差超限的个数;
			int T = MM_raim + KK_raim;						//多系统定位总的卫星个数Totle;
			int i, j;									//为了进行循环;
			int final_N, final_P;
			double X_raim0, Y_raim0, Z_raim0;
			X_raim0 = rcoor_raim.X;
			Y_raim0 = rcoor_raim.Y;
			Z_raim0 = rcoor_raim.Z;

			double xyztch[3]={0};//剔除后坐标xyz0
			double NEUtch[3]={0};//
			//int index;//是否循环计算的标志,也即是是否有粗差的标志;
			double a=0,b=0,c=0;
			do
			{
				if(chaoxian_num>10)
				{
					memset(Bn,0x00,sizeof(int)*20);
					memset(Bp,0x00,sizeof(int)*20);
					memset(BBPC,0x00,sizeof(BS_PR_CR)*20);	
					break;
				}
				//index = 0;
				double	*ll = new	double[T]();		//课本P57参数  等加以double	(*ll)[1]=	 new	double[T][1];
				double	*mm = new	double[T]();
				double	*nn = new	double[T]();
				double	*L = new	double[T]();
				double	*A = new	double[T * 5]();		//状态矩阵A;
				double	*AT = new	double[5 * T]();		//状态矩阵A的转置;
				double	*P = new	double[T*T]();		//权矩阵P;              ()是对动态内存进行初始化
				double	*ATP = new	double[5 * T]();		//A的转置乘以P;
				double	*ATPA = new	double[5 * 5]();		//A的转置乘以P乘以A;
				double	*inv_ATPA = new	double[5 * 5]();		//(A的转置乘以P乘以A)的逆;
				double	*ATPL = new	double[5]();		//A的转置乘以P乘以L;
				double	*result = new	double[5]();		//(A的转置乘以P乘以A)乘以(A的转置乘以P乘以L)，(inv_ATPA)(ATPL);


				double	*AX = new	double[T]();		//A乘以X;
				double  *V = new	double[T]();		//V=AX-L
				double	*VT = new	double[1 * T]();
				double	*VTP = new	double[1 * T]();
				double	*VTPV = new	double[T * 1]();

				///////////////////////////////////////////列法方程;

				//cout<<"系数矩阵B和L"<<endl;																	//
				for (i = 0; i<MM_raim; i++)
				{
					ll[i] = (M2_gps_coor.X[i] - rcoor_raim.X) / M2_GPS_SR[i];
					mm[i] = (M2_gps_coor.Y[i] - rcoor_raim.Y) / M2_GPS_SR[i];
					nn[i] = (M2_gps_coor.Z[i] - rcoor_raim.Z) / M2_GPS_SR[i];
					A[i * 5 + 0] = ll[i];
					A[i * 5 + 1] = mm[i];
					A[i * 5 + 2] = nn[i];
					A[i * 5 + 3] = -1;
					//A[i*5+4]=0;								//初始化了就不需要了
					L[i] = M2_GPS_SR[i] - M2_gps_wj[i];

					//printf("%8.3f%8.3f%8.3f%8.3f%8.3f%16.3f\n",A[i*5+0],A[i*5+1],A[i*5+2],A[i*5+3],A[i*5+4],L[i]);	//

					P[i*T + i] = 1;									//给GPS定的权
				}
				for (j = MM_raim; j<T; j++)
				{
					ll[j] = (M2_bds_coor.X[j - MM_raim] - rcoor_raim.X) / M2_BDS_SR[j - MM_raim];
					mm[j] = (M2_bds_coor.Y[j - MM_raim] - rcoor_raim.Y) / M2_BDS_SR[j - MM_raim];
					nn[j] = (M2_bds_coor.Z[j - MM_raim] - rcoor_raim.Z) / M2_BDS_SR[j - MM_raim];
					A[j * 5 + 0] = ll[j];
					A[j * 5 + 1] = mm[j];
					A[j * 5 + 2] = nn[j];
					//A[j*5+3]=0;								//初始化了就不需要了;
					A[j * 5 + 4] = -1;
					L[j] = M2_BDS_SR[j - MM_raim] - M2_bds_wj[j - MM_raim];

					//printf("%8.3f%8.3f%8.3f%8.3f%8.3f%16.3f\n",A[j*5+0],A[j*5+1],A[j*5+2],A[j*5+3],A[j*5+4],L[j]);	//

					P[j*T + j] = 1;									//给BDS定的权
				}

				///////////////////////////////////////////通过函数的指针进行矩阵的运算，传出需要的矩阵;
				M_Tra(T, 5, A, AT);							//矩阵转置	A的转置		传出AT;
				M_Mul(5, T, T, AT, P, ATP);						//矩阵相乘	AT乘P		传出ATP;
				M_Mul(5, T, 5, ATP, A, ATPA);					//			ATP乘A		传出ATPA;
				M_Inv(5, ATPA, inv_ATPA);						//矩阵求逆	ATPA的逆		传出inv_ATPA;
				M_Mul(5, T, 1, ATP, L, ATPL);					//			ATP乘L		传出ATPL;
				M_Mul(5, 5, 1, inv_ATPA, ATPL, result);			//			inv_ATPA乘ATPL传出result;

				//cout<<inv_ATPA[1]<<inv_ATPA[2]<<inv_ATPA[3]<<inv_ATPA[4]<<inv_ATPA[5]<<endl;
				//cout<<ATPL[1]<<ATPL[2]<<ATPL[3]<<ATPL[4]<<ATPL[5]<<endl;
				if (inv_ATPA != NULL)
				{
					rcoor_raim.X = result[0];
					rcoor_raim.Y = result[1];
					rcoor_raim.Z = result[2];
					rcoor_raim.P1 = result[3];
					rcoor_raim.P2 = result[4];

					for (i = 0; i<5; i++)
						GDOP_raim += inv_ATPA[i * 5 + i];
					sate_num.GDOP_raim = sqrt(GDOP_raim);
					for (i = 0; i<3; i++)
						PDOP_raim += inv_ATPA[i * 5 + i];
					sate_num.PDOP_raim = sqrt(PDOP_raim);
				}
				else
				{
					rcoor_raim.X = 0;
					rcoor_raim.Y = 0;
					rcoor_raim.Z = 0;
					rcoor_raim.P1 = 0;
					rcoor_raim.P2 = 0;
					//printf("这个历元数据无法求解!\n");
					//system("pause");
				}

				double X[5][1];
				X[0][0] = rcoor_raim.X;
				X[0][1] = rcoor_raim.Y;
				X[0][2] = rcoor_raim.Z;
				X[0][3] = rcoor_raim.P1;
				X[0][4] = rcoor_raim.P2;
				//double	*AX=	new	double[T]();			//A乘以X;
				M_Mul(T, 5, 1, A, X[0], AX);							//矩阵相乘;
				//double  *V=		new	double[T]();			//V=AX-L

				for (int p = 0; p<T; p++)
				{
					V[p] = AX[p] - L[p];
				}
				//double *VT=		new	double[1*T]();
				//double *VTP=	new	double[1*T]();
				//double *VTPV=	new	double[T*1]();

				M_Tra(T, 1, V, VT);								//矩阵转置	A的转置		传出AT;
				M_Mul(1, T, T, VT, P, VTP);							//矩阵相乘	AT乘P		传出ATP;
				M_Mul(1, T, 1, VTP, V, VTPV);
				double RMS_raim = sqrt(*VTPV / (T - 5));
				double w[32];
				for (i = 0; i<T; i++)
				{
					w[i] = fabs(V[i]) / (RMS_raim*sqrt((T - 1.0) / T));
					//printf("%16.8f\n",w[i]);				//
				}
				double w1=0.0;int n_s=0;
				for(i=0;i<T;i++)
				{
					if(w[i]> w1)
					{
						w1=w[i];
						n_s=i;
					}
				}
				/*if(n_s<MM_raim)
				{

				}*/
				int NNN,PPP;
				NNN = MM_raim;
				PPP = KK_raim;
				//index = 1;				//说明有问题，要回代;



				if (n_s>NNN - 1)			//说明是BDS卫星的
				{
					bad_BPRN[chaoxian_num] = M2_BPRN[n_s - NNN];//如果GPS7颗，BDS9颗，现在pp=8，也就是w中第9个，那么就是BDS卫星的第2个对应于1，即8-7=1;
					//chaoxian_num++;
					for(int j=1;j<5;j++)//四个基准站，依次消除坏星
					{
						for (int m=0;m<Bp[j];m++)//从0开始依次比对prn
						{
							if (bad_BPRN[chaoxian_num]==BBPC[j].C_PRN[m])//当prn相同时就消除这颗卫星对应的内容
							{
								for (int s = m; s<Bp[j]; s++)//从坏星开始将后一个星内容覆盖前一个卫星内容
								{
									/*M2_bds_coor.X[s - NNN] = M2_bds_coor.X[s - NNN + 1];
									M2_bds_coor.Y[s - NNN] = M2_bds_coor.Y[s - NNN + 1];
									M2_bds_coor.Z[s - NNN] = M2_bds_coor.Z[s - NNN + 1];
									M2_BDS_SR[s - NNN] = M2_BDS_SR[s - NNN + 1];
									M2_bds_wj[s - NNN] = M2_bds_wj[s - NNN + 1];
									BBPC[j].C_PRN[s - NNN]=BBPC[j].C_PRN[s - NNN+1];
									BBPC[j].CPC[s - NNN]=BBPC[j].CPC[s - NNN+1];*/
									BBPC[j].C_PRN[s]=BBPC[j].C_PRN[s+1];
									BBPC[j].CPC[s]=BBPC[j].CPC[s+1];
								}
								Bp[j]--;
								break;
							}
						}
					}
					/*for(int j=1;j<5;j++)
					{
					Bp[j]--;
					}*/
					B_bad_num++;
					KK_raim = PPP - 1;		//新的BDS卫星个数
					chaoxian_num++;
				}
				else					//说明是GPS卫星的
				{
					bad_GPRN[chaoxian_num] = M2_GPRN[n_s];
					for(int j=1;j<5;j++)//四个基准站，依次消除坏星
					{
						for (int m=0;m<Bn[j];m++)//从0开始依次比对prn
						{
							if (bad_GPRN[chaoxian_num]==BBPC[j].G_PRN[m])//当prn相同时就消除这颗卫星对应的内容
							{
								for (int s = m; s<Bn[j]; s++)//从坏星开始将后一个星内容覆盖前一个卫星内容
								{
									/*M2_bds_coor.X[s - NNN] = M2_bds_coor.X[s - NNN + 1];
									M2_bds_coor.Y[s - NNN] = M2_bds_coor.Y[s - NNN + 1];
									M2_bds_coor.Z[s - NNN] = M2_bds_coor.Z[s - NNN + 1];
									M2_BDS_SR[s - NNN] = M2_BDS_SR[s - NNN + 1];
									M2_bds_wj[s - NNN] = M2_bds_wj[s - NNN + 1];
									BBPC[j].C_PRN[s - NNN]=BBPC[j].C_PRN[s - NNN+1];
									BBPC[j].CPC[s - NNN]=BBPC[j].CPC[s - NNN+1];*/
									BBPC[j].G_PRN[s]=BBPC[j].G_PRN[s+1];
									BBPC[j].GPC[s]=BBPC[j].GPC[s+1];
								}
								Bn[j]--;
								break;
							}
						}
					}
					G_bad_num++;
					MM_raim = NNN - 1;		//新的GPS卫星个数
					chaoxian_num++;
					//for (int s = n_s; s<NNN; s++)
					//{
					//	/*M2_gps_coor.X[s ] = M2_gps_coor.X[s + 1 ];
					//	M2_gps_coor.Y[s ] = M2_gps_coor.Y[s + 1 ];
					//	M2_gps_coor.Z[s ] = M2_gps_coor.Z[s + 1 ];
					//	M2_GPS_SR[s ] = M2_GPS_SR[s + 1 ];
					//	M2_gps_wj[s ] = M2_gps_wj[s + 1 ];*/
					//for(int j=1;j<5;j++)
					//	{
					//		BBPC[j].G_PRN[s ]=BBPC[j].G_PRN[s+1];
					//		BBPC[j].GPC[s ]=BBPC[j].GPC[s+1];
					//	}
					//}
					//for(int j=1;j<5;j++)
					//	{
					//		Bn[j]--;
					//	}

				}

				KK2=KK_raim;MM2=MM_raim;

				MOVING_POS_MODULE4(xyz2ldz6,BBPC, dg0, geph, rcoor2, sate_num,Bn, Bp);
				if(rcoor2.X!=0)
				{
					xyztch[0]=rcoor2.X;xyztch[1]=rcoor2.Y;xyztch[2]=rcoor2.Z;
					XYZ2NEU(m_iofh[4].xyz,xyztch,NEUtch);//NEU4差分改正后xyz0相对于真值的NEU，用于评定精度
				}
				else
				{
					NEUtch[0]=0;
					NEUtch[1]=0;
					NEUtch[2]=0;
					memset(Bn,0x00,sizeof(int)*20);
					memset(Bp,0x00,sizeof(int)*20);
					memset(BBPC,0x00,sizeof(BS_PR_CR)*20);
					break;
				}

				a=fabs(NEUtch[0]);
				b=fabs(NEUtch[1]);
				c=fabs(NEUtch[2]);
			}while(a>2.0||b>2.0||c>4.0);//N,E,U限差224m，经过半天采集应设为112m
		}

	}
	if (rcoor2.X != 0 && MM2 != 0 && KK2 != 0)
	{
		sate_num.KK2 = KK2;
		sate_num.MM2 = MM2;
		sate_num.ALL_GB2 = ALL_GB2;
		sate_num.delX2 = rcoor2.X;
		sate_num.delY2 = rcoor2.Y;
		sate_num.delZ2 = rcoor2.Z;
		sate_num.M2_P1 = rcoor2.P1;
		sate_num.M2_P2 = rcoor2.P2;
		sate_num.GDOP2 = GDOP2;
		sate_num.PDOP2 = PDOP2;
	}
}

/*主程序*/
//void CNDGNSS::NDGNSS_MAIN(DATG dg[],GEPH geph[MAXPRN_NUM],IOFH ih[],
//					  sCoorCartesian &rcoor,double &tratio,int epnum)
void CNDGNSS::NDGNSS_MAIN(DATG dg0[], GEPH geph[MAXPRN_NUM], IOFH ih0[], Sate_NUM &sate_num, int &B1n, int &B1p, int &B2n, int &B2p, int &B3n, int &B3p, BS_PR_CR &B1BPC, BS_PR_CR &B2BPC, BS_PR_CR &B3BPC)
{
#pragma region NDGNSS
#if 1

	DATG dg[5] = { 0 };
	IOFH ih[5] = { 0 };
	for (int i = 0; i < 3; i++)//123为基准站
	{
		dg[i + 2] = dg0[i];
		ih[i + 2] = ih0[i];
	}




	int		NN = 0, PP = 0, QQ = 0;						//可利用GPS,BDS,GLONASS卫星数,这里再一次定义是为了将其输出;
	double	GDOP_raim = 0, PDOP_raim = 0, GDOP1 = 0, PDOP1 = 0, GDOP2 = 0, PDOP2 = 0;

	/************▼基准站改正值计算▼↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/

	//当前程序dg[2]<主控站>,dg[3]<监测站>,dg[4]<监测站>为基准站B1,B2,B3,dg[0]为流动站M（待求）;

	int	B1gps_num = 0, B1bds_num = 0, B1glo_num = 0;					//基准站1当前历元GPS、BDS可见卫星数
	int	B2gps_num = 0, B2bds_num = 0, B2glo_num = 0;					//基准站2当前历元GPS、BDS可见卫星数
	int	B3gps_num = 0, B3bds_num = 0, B3glo_num = 0;					//基准站3当前历元GPS、BDS可见卫星数
	for (int ii = 0; ii < dg[2].nsat; ii++)
	{
		if (dg[2].prn[ii] <= 32)
			B1gps_num++;							//基准站1当前历元GPS可见卫星数
		if (dg[2].prn[ii] >= 38 && dg[2].prn[ii] <= 61)
			B1glo_num++;							//基准站1当前历元GLO可见卫星数
		if (dg[2].prn[ii] >= 161 && dg[2].prn[ii] <= 197)
			B1bds_num++;							//基准站1当前历元BDS可见卫星数
	}
	for (int ii = 0; ii < dg[3].nsat; ii++)
	{
		if (dg[3].prn[ii] <= 32)
			B2gps_num++;							//基准站2当前历元GPS可见卫星数
		if (dg[3].prn[ii] >= 38 && dg[3].prn[ii] <= 61)
			B2glo_num++;							//基准站2当前历元GLO可见卫星数
		if (dg[3].prn[ii] >= 161 && dg[3].prn[ii] <= 197)
			B2bds_num++;							//基准站2当前历元BDS可见卫星数
	}
	for (int ii = 0; ii < dg[4].nsat; ii++)
	{
		if (dg[4].prn[ii] <= 32)
			B3gps_num++;							//基准站3当前历元GPS可见卫星数
		if (dg[4].prn[ii] >= 38 && dg[4].prn[ii] <= 61)
			B3glo_num++;							//基准站3当前历元GLO可见卫星数
		if (dg[4].prn[ii] >= 161 && dg[4].prn[ii] <= 197)
			B3bds_num++;							//基准站3当前历元BDS可见卫星数
	}

	//int M1gps_num = 0, M1bds_num = 0, M1glo_num = 0;	//<流动站1/2>GPS可见卫星数
	//for (int ii = 0; ii<dg[1].nsat; ii++)
	//{
	//	if (dg[1].prn[ii] <= 33)
	//		M1gps_num++;
	//	if (dg[1].prn[ii] >= 38 && dg[1].prn[ii] <= 61)
	//		M1glo_num++;
	//	if (dg[1].prn[ii] >= 161 && dg[1].prn[ii] <= 197)
	//		M1bds_num++;
	//}

	if (B1gps_num>0 && B2gps_num > 0 && B3gps_num > 0 && B1bds_num > 0 && B2bds_num > 0 && B3bds_num > 0)//在3个基准站和1个流动站数据都正常的情况下进行解算								
	{

		double	B1gps_wj[32] = { 0 }, B1GPS_SR[32] = { 0 }, B1bds_wj[35] = { 0 }, B1BDS_SR[35] = { 0 };
		double	B2gps_wj[32] = { 0 }, B2GPS_SR[32] = { 0 }, B2bds_wj[35] = { 0 }, B2BDS_SR[35] = { 0 };
		double	B3gps_wj[32] = { 0 }, B3GPS_SR[32] = { 0 }, B3bds_wj[35] = { 0 }, B3BDS_SR[35] = { 0 };

		sp		B1gps_coor = { 0 }, B1bds_coor = { 0 };		//基准站1卫星坐标_结构体
		sp		B2gps_coor = { 0 }, B2bds_coor = { 0 };		//基准站2卫星坐标_结构体
		sp		B3gps_coor = { 0 }, B3bds_coor = { 0 };		//基准站3卫星坐标_结构体

		//B1BPC = { 0 };							//基准站1伪距改正结构体
		//B2BPC = { 0 };							//基准站2伪距改正结构体
		//B3BPC = { 0 };							//基准站3伪距改正结构体
		//BS_PR_CR BPC = { 0 }, BPC_raim = { 0 };				//基准站1,2,3通过反距离加权后的伪距改正结构体

		double	B1X, B1Y, B1Z;							//基准站1坐标
		double	B2X, B2Y, B2Z;							//基准站2坐标
		double	B3X, B3Y, B3Z;							//基准站3坐标

		double  g_swj, g_R, b_swj, b_R;				//基准站可以公用
		double	G_XK, G_YK, G_ZK;							//基准站可以公用,当前历元GPS系统基准站对应的卫星坐标
		double	B_XK, B_YK, B_ZK;						//基准站可以公用,当前历元BDS系统基准站对应的卫星坐标
		double	R_XK, R_YK, R_ZK;						//基准站可以公用,当前历元GLONASS系统基准站对应的卫星坐标
		//int		g_PRN[32]={0}	,b_PRN[35]={0};

		//▼▼▼基准站1<主控站>▼▼▼;						
		//B1X0= -2101604.675;							//基准站1<主控站>精确坐标;	  	
		//B1Y0= 4613380.003;
		//B1Z0= 3857666.137;
		B1X = ih[2].xyz[0];
		B1Y = ih[2].xyz[1];
		B1Z = ih[2].xyz[2];

		B1n = 0, B1p = 0;								//n为GPS可利用卫星数
		for (int jj = 0; jj < B1gps_num; jj++)
		{
			g_swj = 0, g_R = 0;
			G_XK = 0, G_YK = 0, G_ZK = 0;
			GNSS_POS_MODULE(geph, dg, 2, B1X, B1Y, B1Z, &g_swj, &g_R, &G_XK, &G_YK, &G_ZK, jj, 1);//dg后面的参数为站号,0,1,2,3,为了配合dg【】中的号,最后一位整数1为GPS系统，2为BDS系统;
			if (g_swj != 0 && g_R != 0)
			{
				B1gps_wj[B1n] = g_swj;
				B1GPS_SR[B1n] = g_R;
				B1BPC.GPC[B1n] = g_R - g_swj;
				B1BPC.G_PRN[B1n] = dg[2].prn[jj];
				B1gps_coor.X[B1n] = G_XK;
				B1gps_coor.Y[B1n] = G_YK;
				B1gps_coor.Z[B1n] = G_ZK;
				B1n++;								//n为可利用GPS卫星数目
			}
		}
		for (int jj = B1gps_num + B1glo_num; jj < dg[2].nsat; jj++)
		{
			b_swj = 0, b_R = 0;
			B_XK = 0, B_YK = 0, B_ZK = 0;
			GNSS_POS_MODULE(geph, dg, 2, B1X, B1Y, B1Z, &b_swj, &b_R, &B_XK, &B_YK, &B_ZK, jj, 2);//dg后面的参数为站号,0,1,2,3,为了配合dg【】中的号，最后一位整数1为GPS系统，2为BDS系统;
			if (b_swj != 0 && b_R != 0)
			{
				B1bds_wj[B1p] = b_swj;
				B1BDS_SR[B1p] = b_R;
				B1BPC.CPC[B1p] = b_R - b_swj;
				B1BPC.C_PRN[B1p] = dg[2].prn[jj];
				B1bds_coor.X[B1p] = B_XK;
				B1bds_coor.Y[B1p] = B_YK;
				B1bds_coor.Z[B1p] = B_ZK;
				B1p++;								//n为可利用GPS卫星数目
			}
		}
		//▼▼▼基准站2<监测站>▼▼▼;			
		//B2X0=-2124070.8115;							//基准站2精确坐标;-2198414.3006  4612415.3463  3804732.3193
		//B2Y0= 4491059.9645;
		//B2Z0= 3986562.0410;
		B2X = ih[3].xyz[0];
		B2Y = ih[3].xyz[1];
		B2Z = ih[3].xyz[2];

		B2n = 0, B2p = 0;								//n为GPS可利用卫星数
		for (int jj = 0; jj < B2gps_num; jj++)
		{
			g_swj = 0, g_R = 0;
			G_XK = 0, G_YK = 0, G_ZK = 0;
			GNSS_POS_MODULE(geph, dg, 3, B2X, B2Y, B2Z, &g_swj, &g_R, &G_XK, &G_YK, &G_ZK, jj, 1);//dg后面的参数为站号,0,1,2,3,为了配合dg【】中的号,最后一位整数1为GPS系统，2为BDS系统;
			if (g_swj != 0 && g_R != 0)
			{
				B2gps_wj[B2n] = g_swj;
				B2GPS_SR[B2n] = g_R;
				B2BPC.GPC[B2n] = g_R - g_swj;
				B2BPC.G_PRN[B2n] = dg[3].prn[jj];
				B2gps_coor.X[B2n] = G_XK;
				B2gps_coor.Y[B2n] = G_YK;
				B2gps_coor.Z[B2n] = G_ZK;
				B2n++;								//n为可利用GPS卫星数目
			}
		}
		for (int jj = B2gps_num + B2glo_num; jj < dg[3].nsat; jj++)
		{
			b_swj = 0, b_R = 0;
			B_XK = 0, B_YK = 0, B_ZK = 0;
			GNSS_POS_MODULE(geph, dg, 3, B2X, B2Y, B2Z, &b_swj, &b_R, &B_XK, &B_YK, &B_ZK, jj, 2);//dg后面的参数为站号,0,1,2,3,为了配合dg【】中的号，最后一位整数1为GPS系统，2为BDS系统;
			if (b_swj != 0 && b_R != 0)
			{
				B2bds_wj[B2p] = b_swj;
				B2BDS_SR[B2p] = b_R;
				B2BPC.CPC[B2p] = b_R - b_swj;
				B2BPC.C_PRN[B2p] = dg[3].prn[jj];
				B2bds_coor.X[B2p] = B_XK;
				B2bds_coor.Y[B2p] = B_YK;
				B2bds_coor.Z[B2p] = B_ZK;
				B2p++;								//n为可利用GPS卫星数目
			}
		}
		//▼▼▼基准站3<监测站>▼▼▼;						
		//B3X0=-2258698.2613;							//基准站3精确坐标;-2258698.2613  4493782.5391  3909206.8862
		//B3Y0= 4493782.5391;
		//B3Z0= 3909206.8862;
		B3X = ih[4].xyz[0];
		B3Y = ih[4].xyz[1];
		B3Z = ih[4].xyz[2];

		B3n = 0, B3p = 0;								//n为GPS可利用卫星数
		for (int jj = 0; jj < B3gps_num; jj++)
		{
			g_swj = 0, g_R = 0;
			G_XK = 0, G_YK = 0, G_ZK = 0;
			GNSS_POS_MODULE(geph, dg, 4, B3X, B3Y, B3Z, &g_swj, &g_R, &G_XK, &G_YK, &G_ZK, jj, 1);//dg后面的参数为站号,0,1,2,3,为了配合dg【】中的号,最后一位整数1为GPS系统，2为BDS系统;
			if (g_swj != 0 && g_R != 0)
			{
				B3gps_wj[B3n] = g_swj;
				B3GPS_SR[B3n] = g_R;
				B3BPC.GPC[B3n] = g_R - g_swj;
				B3BPC.G_PRN[B3n] = dg[4].prn[jj];
				B3gps_coor.X[B3n] = G_XK;
				B3gps_coor.Y[B3n] = G_YK;
				B3gps_coor.Z[B3n] = G_ZK;
				B3n++;								//n为可利用GPS卫星数目
			}
		}
		for (int jj = B3gps_num + B3glo_num; jj < dg[4].nsat; jj++)
		{
			b_swj = 0, b_R = 0;
			B_XK = 0, B_YK = 0, B_ZK = 0;
			GNSS_POS_MODULE(geph, dg, 4, B3X, B3Y, B3Z, &b_swj, &b_R, &B_XK, &B_YK, &B_ZK, jj, 2);//dg后面的参数为站号,0,1,2,3,为了配合dg【】中的号，最后一位整数1为GPS系统，2为BDS系统;
			if (b_swj != 0 && b_R != 0)
			{
				B3bds_wj[B3p] = b_swj;
				B3BDS_SR[B3p] = b_R;
				B3BPC.CPC[B3p] = b_R - b_swj;
				B3BPC.C_PRN[B3p] = dg[4].prn[jj];
				B3bds_coor.X[B3p] = B_XK;
				B3bds_coor.Y[B3p] = B_YK;
				B3bds_coor.Z[B3p] = B_ZK;
				B3p++;								//n为可利用GPS卫星数目
			}
		}

		fprintf(BPC_fil, "%5d,%3d,%3d,%3d,%3d,%3d,%3d\n", int(dg[2].tg.second), B1n, B2n, B3n, B1p, B2p, B3p);
		for (int u = 0; u < B1n; u++)
			fprintf(BPC_fil, "%10d,%10.3f,%10.3f,%10.3f\n", B1BPC.G_PRN[u], B1BPC.GPC[u],B1gps_wj[u],B1GPS_SR[u]);
		for (int u = 0; u < B2n; u++)
			fprintf(BPC_fil, "%10d,%10.3f,%10.3f,%10.3f\n", B2BPC.G_PRN[u], B2BPC.GPC[u],B2gps_wj[u],B2GPS_SR[u]);
		for (int u = 0; u < B3n; u++)
			fprintf(BPC_fil, "%10d,%10.3f,%10.3f,%10.3f\n", B3BPC.G_PRN[u], B3BPC.GPC[u],B3gps_wj[u],B3GPS_SR[u]);
		for (int r = 0; r < B1p; r++)
			fprintf(BPC_fil, "%10d,%10.3f,%10.3f,%10.3f\n", B1BPC.C_PRN[r], B1BPC.CPC[r],B1bds_wj[r],B1BDS_SR[r]);
		for (int r = 0; r < B2p; r++)
			fprintf(BPC_fil, "%10d,%10.3f,%10.3f,%10.3f\n", B2BPC.C_PRN[r], B2BPC.CPC[r],B2bds_wj[r],B2BDS_SR[r]);
		for (int r = 0; r < B3p; r++)
			fprintf(BPC_fil, "%10d,%10.3f,%10.3f,%10.3f\n", B3BPC.C_PRN[r], B3BPC.CPC[r],B3bds_wj[r],B3BDS_SR[r]);


	}//开始那个if判断各站数据接收是否正确的判断结尾
#endif
#pragma endregion
}


/*主程序*多基准站内插网格伪距改正值*/
//void CNDGNSS::NDGNSS_MAIN(DATG dg[],GEPH geph[MAXPRN_NUM],IOFH ih[],
//					  sCoorCartesian &rcoor,double &tratio,int epnum)
void CNDGNSS::GRID_NDGNSS_MAIN(DATG dg0[], GEPH geph[MAXPRN_NUM], IOFH ih0[], Sate_NUM &sate_num, int Bn[], int Bp[], BS_PR_CR BBPC[],int NO_JZZ)
{
#pragma region NDGNSS
#if 1

	DATG dg2[20] = { 0 };
	IOFH ih2[20] = { 0 };
	for (int i = 0; i < NO_JZZ-1; i++)//1234为基准站,多少基准站站就设为几NO_JZZ-1！！！！！！！4基准站1流动站,现在四个基准站！！！0,1,2，3
	{
		dg2[i + 1] = dg0[i];
		ih2[i + 1] = ih0[i];
	}




	int		NN = 0, PP = 0, QQ = 0;						//可利用GPS,BDS,GLONASS卫星数,这里再一次定义是为了将其输出;
	double	GDOP_raim = 0, PDOP_raim = 0, GDOP1 = 0, PDOP1 = 0, GDOP2 = 0, PDOP2 = 0;

	/************▼基准站改正值计算▼↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/

	//当前程序dg[2]<主控站>,dg[3]<监测站>,dg[4]<监测站>为基准站B1,B2,B3,dg[0]为流动站M（待求）;

	int	Bgps_num[20] = {0}, Bbds_num[20] = {0}, Bglo_num[20] = {0};					//基准站当前历元GPS、BDS可见卫星数
	for (int Njzz=1; Njzz < NO_JZZ; Njzz++)                                //基准站个数Njzz，统计所有基准站各类卫星数目,四川北区现在共4个基准站1流动站
	{
		for (int ii = 0; ii < dg2[Njzz].nsat; ii++)          //第Njzz个基准站的卫星数，出错！！！
		{
			if (dg2[Njzz].prn[ii] <= 32)
				Bgps_num[Njzz]++;							//基准站Njjz当前历元GPS可见卫星数，出错！！！
			if (dg2[Njzz].prn[ii] >= 38 && dg2[Njzz].prn[ii] <= 61)
				Bglo_num[Njzz]++;							//基准站Njzz当前历元GLO可见卫星数，出错！！！
			if (dg2[Njzz].prn[ii] >= 161 && dg2[Njzz].prn[ii] <= 197)
				Bbds_num[Njzz]++;							//基准站Njzz当前历元BDS可见卫星数，出错！！！
		}
	}

	double LCG[50]={0}, LCB[50]={0};
	LCG[0]=1;LCB[0]=1;
	for (int i=1;i< NO_JZZ;i++)              //现在三个基准站！！！1,2,3
	{
		LCG[i]=LCG[i-1]*Bgps_num[i];
		LCB[i]=LCB[i-1]*Bgps_num[i];
	}
	//if (Bgps_num[1]>0 && Bgps_num[2] > 0 && Bgps_num[3] > 0 && Bgps_num[4]>0 && // Bgps_num[5] > 0 &&Bgps_num[6] > 0 &&
	//	Bbds_num[1]>0 && Bbds_num[2] > 0 && Bbds_num[3] > 0 && Bbds_num[4]>0  //  && Bbds_num[5] > 0 && Bbds_num[6] > 0
	//	)//在4个基准站和1个流动站数据都正常的情况下进行解算								
	if(LCG[NO_JZZ-1]>0&&LCB[NO_JZZ-1]>0)
	{

		double	Bgps_wj[20][32] = { 0 }, BGPS_SR[20][32] = { 0 }, Bbds_wj[20][35] = { 0 }, BBDS_SR[20][35] = { 0 };
		sp		Bgps_coor[20] = { 0 }, Bbds_coor[20] = { 0 };		        //基准站1卫星坐标_结构体
		double	BX[20]={0};double BBY[20]={0};double BZ[20]={0};							//基准站1坐标
		double  g_swj=0, g_R=0, b_swj=0, b_R=0;				                //基准站可以公用
		double	G_XK=0, G_YK=0, G_ZK=0;					    //基准站可以公用,当前历元GPS系统基准站对应的卫星坐标
		double	B_XK=0, B_YK=0, B_ZK=0;						//基准站可以公用,当前历元BDS系统基准站对应的卫星坐标
		double	R_XK=0, R_YK=0, R_ZK=0;						//基准站可以公用,当前历元GLONASS系统基准站对应的卫星坐标
		//double  SUM_GPC[20]={0}, SUM_CPC[20]={0}, MEAN_GPC[20]={0}, MEAN_CPC[20]={0} ,MEAN_GCPC[20]={0};       //GPC,CPC分别求和求平均

		//▼▼▼基准站▼▼▼;						

		for(int Njz=1; Njz<NO_JZZ;Njz++)              //四川北区现在共4个基准站1个流动站,现在四个基准站！！！1,2,3，4
		{
			BX[Njz] = ih2[Njz].xyz[0];
			BBY[Njz] = ih2[Njz].xyz[1];
			BZ[Njz] = ih2[Njz].xyz[2];
			Bn[Njz] = 0, Bp[Njz] = 0;								//n为GPS可利用卫星数
			for (int jj = 0; jj < Bgps_num[Njz]; jj++)
			{
				g_swj = 0, g_R = 0;
				G_XK = 0, G_YK = 0, G_ZK = 0;
				GNSS_POS_MODULE(geph, dg2, Njz, BX[Njz], BBY[Njz], BZ[Njz], &g_swj, &g_R, &G_XK, &G_YK, &G_ZK, jj, 1);//*****dg后面的参数为站号,Njz,(0,1,2,3,4……)为了配合dg【】中的号,最后一位整数1为GPS系统，2为BDS系统!!!!!!!!!!!!!;
				if (g_swj != 0 && g_R != 0)
				{
					Bgps_wj[Njz][Bn[Njz]] = g_swj;
					BGPS_SR[Njz][Bn[Njz]] = g_R;
					BBPC[Njz].GPC[Bn[Njz]] = g_R - g_swj;
					BBPC[Njz].G_PRN[Bn[Njz]] = dg2[Njz].prn[jj];
					Bgps_coor[Njz].X[Bn[Njz]] = G_XK;
					Bgps_coor[Njz].Y[Bn[Njz]] = G_YK;
					Bgps_coor[Njz].Z[Bn[Njz]] = G_ZK;
					//SUM_GPC[Njz]+=BBPC[Njz].GPC[Bn[Njz]];
					Bn[Njz]++;								        //Bn[Njz]为可利用GPS卫星数目	
				}
			}
			//MEAN_GPC[Njz]=SUM_GPC[Njz]/Bn[Njz];
			////for (int m=0;m<Bn[Njz];m++){BBPC[Njz].GPC[m]=BBPC[Njz].GPC[m]-MEAN_GPC[Njz];}//Bn[Njz]为可利用GPS卫星数目,从0开始算，所以小于Bn[Njz]
			for (int jj = Bgps_num[Njz] + Bglo_num[Njz]; jj < dg2[Njz].nsat; jj++)
			{
				b_swj = 0, b_R = 0;
				B_XK = 0, B_YK = 0, B_ZK = 0;
				GNSS_POS_MODULE(geph, dg2, Njz, BX[Njz], BBY[Njz], BZ[Njz], &b_swj, &b_R, &B_XK, &B_YK, &B_ZK, jj, 2);//dg后面的参数为站号,0,1,2,3,为了配合dg【】中的号，最后一位整数1为GPS系统，2为BDS系统;
				if (b_swj != 0 && b_R != 0)
				{
					Bbds_wj[Njz][Bp[Njz]] = b_swj;
					BBDS_SR[Njz][Bp[Njz]] = b_R;
					BBPC[Njz].CPC[Bp[Njz]] = b_R - b_swj;
					BBPC[Njz].C_PRN[Bp[Njz]] = dg2[Njz].prn[jj];
					Bbds_coor[Njz].X[Bp[Njz]] = B_XK;
					Bbds_coor[Njz].Y[Bp[Njz]] = B_YK;
					Bbds_coor[Njz].Z[Bp[Njz]] = B_ZK;
					//SUM_CPC[Njz]+=BBPC[Njz].CPC[Bp[Njz]];
					Bp[Njz]++;								//Bp[Njz]为可利用GPS卫星数目
				}
			}
			////MEAN_CPC[Njz]=SUM_CPC[Njz]/Bp[Njz];
			////MEAN_GCPC[Njz]=(SUM_GPC[Njz]+SUM_CPC[Njz])/(Bn[Njz]+Bp[Njz]);
			//for (int m=0;m<Bn[Njz];m++){BBPC[Njz].GPC[m]=BBPC[Njz].GPC[m]-MEAN_GPC[Njz];}
			//for (int m=0;m<Bp[Njz];m++){BBPC[Njz].CPC[m]=BBPC[Njz].CPC[m]-MEAN_GPC[Njz];}//Bn[Njz]为可利用GPS卫星数目,从0开始算，所以小于Bn[Njz]
		}
		fprintf(BPC_fil, "%5d\n",int(dg2[2].tg.second));
		for (int njzz=1; njzz< NO_JZZ; njzz++)      //基准站个数Njzz，统计所有基准站各类卫星数目,河北现在共4个基准站1个流动站              
		{
			fprintf(BPC_fil, "%2d  G:%3d  C:%3d\n", njzz, Bn[njzz],Bp[njzz]);
			for (int u = 0; u < Bn[njzz]; u++)
				fprintf(BPC_fil, "%3d  G%2d,%10.3f,%10.3f,%10.3f\n", njzz,BBPC[njzz].G_PRN[u], BBPC[njzz].GPC[u],Bgps_wj[njzz][u],BGPS_SR[njzz][u]);
			for (int r = 0; r < Bp[njzz]; r++)
				fprintf(BPC_fil, "%3d C%3d,%10.3f,%10.3f,%10.3f\n", njzz,BBPC[njzz].C_PRN[r], BBPC[njzz].CPC[r],Bbds_wj[njzz][r],BBDS_SR[njzz][r]);
		}

	}//开始那个if判断各站数据接收是否正确的判断结尾
#endif
#pragma endregion
}

void CNDGNSS::GRID_NDGNSS_MAIN_MATCH(DATG dg0[], GEPH geph[MAXPRN_NUM], IOFH ih0[], Sate_NUM &sate_num, int Bn[], int Bp[], BS_PR_CR BBPC[],int NO_JZZ)
{
#pragma region NDGNSS
#if 1

	DATG dg2[20] = { 0 };
	IOFH ih2[20] = { 0 };
	for (int i = 0; i < NO_JZZ-1; i++)//1234为基准站,多少基准站站就设为几NO_JZZ-1！！！！！！！4基准站1流动站,现在四个基准站！！！0,1,2，3
	{
		dg2[i + 1] = dg0[i];
		ih2[i + 1] = ih0[i];
	}




	int		NN = 0, PP = 0, QQ = 0;						//可利用GPS,BDS,GLONASS卫星数,这里再一次定义是为了将其输出;
	double	GDOP_raim = 0, PDOP_raim = 0, GDOP1 = 0, PDOP1 = 0, GDOP2 = 0, PDOP2 = 0;

	/************▼基准站改正值计算▼↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/

	//当前程序dg[2]<主控站>,dg[3]<监测站>,dg[4]<监测站>为基准站B1,B2,B3,dg[0]为流动站M（待求）;

	int	Bgps_num[20] = {0}, Bbds_num[20] = {0}, Bglo_num[20] = {0};					//基准站当前历元GPS、BDS可见卫星数
	for (int Njzz=1; Njzz < NO_JZZ; Njzz++)                                //基准站个数Njzz，统计所有基准站各类卫星数目,四川北区现在共4个基准站1流动站
	{
		for (int ii = 0; ii < dg2[Njzz].nsat; ii++)          //第Njzz个基准站的卫星数，出错！！！
		{
			if (dg2[Njzz].prn[ii] <= 32)
				Bgps_num[Njzz]++;							//基准站Njjz当前历元GPS可见卫星数，出错！！！
			if (dg2[Njzz].prn[ii] >= 38 && dg2[Njzz].prn[ii] <= 61)
				Bglo_num[Njzz]++;							//基准站Njzz当前历元GLO可见卫星数，出错！！！
			if (dg2[Njzz].prn[ii] >= 161 && dg2[Njzz].prn[ii] <= 197)
				Bbds_num[Njzz]++;							//基准站Njzz当前历元BDS可见卫星数，出错！！！
		}
	}

	double LCG[50]={0}, LCB[50]={0};
	LCG[0]=1;LCB[0]=1;
	for (int i=1;i< NO_JZZ;i++)              //现在三个基准站！！！1,2,3
	{
		LCG[i]=LCG[i-1]*Bgps_num[i];
		LCB[i]=LCB[i-1]*Bgps_num[i];
	}
	//if (Bgps_num[1]>0 && Bgps_num[2] > 0 && Bgps_num[3] > 0 && Bgps_num[4]>0 && // Bgps_num[5] > 0 &&Bgps_num[6] > 0 &&
	//	Bbds_num[1]>0 && Bbds_num[2] > 0 && Bbds_num[3] > 0 && Bbds_num[4]>0  //  && Bbds_num[5] > 0 && Bbds_num[6] > 0
	//	)//在4个基准站和1个流动站数据都正常的情况下进行解算								
	if(LCG[NO_JZZ-1]>0&&LCB[NO_JZZ-1]>0)
	{

		double	Bgps_wj[20][32] = { 0 }, BGPS_SR[20][32] = { 0 }, Bbds_wj[20][35] = { 0 }, BBDS_SR[20][35] = { 0 };
		sp		Bgps_coor[20] = { 0 }, Bbds_coor[20] = { 0 };		        //基准站1卫星坐标_结构体
		double	BX[20]={0};double BBY[20]={0};double BZ[20]={0};							//基准站1坐标
		double  g_swj=0, g_R=0, b_swj=0, b_R=0;				                //基准站可以公用
		double	G_XK=0, G_YK=0, G_ZK=0;					    //基准站可以公用,当前历元GPS系统基准站对应的卫星坐标
		double	B_XK=0, B_YK=0, B_ZK=0;						//基准站可以公用,当前历元BDS系统基准站对应的卫星坐标
		double	R_XK=0, R_YK=0, R_ZK=0;						//基准站可以公用,当前历元GLONASS系统基准站对应的卫星坐标
		//double  SUM_GPC[20]={0}, SUM_CPC[20]={0}, MEAN_GPC[20]={0}, MEAN_CPC[20]={0} ,MEAN_GCPC[20]={0};       //GPC,CPC分别求和求平均

		//▼▼▼基准站▼▼▼;						

		for(int Njz=1; Njz<NO_JZZ;Njz++)              //四川北区现在共4个基准站1个流动站,现在四个基准站！！！1,2,3，4
		{
			BX[Njz] = ih2[Njz].xyz[0];
			BBY[Njz] = ih2[Njz].xyz[1];
			BZ[Njz] = ih2[Njz].xyz[2];
			Bn[Njz] = 0, Bp[Njz] = 0;								//n为GPS可利用卫星数
			for (int jj = 0; jj < Bgps_num[Njz]; jj++)
			{
				g_swj = 0, g_R = 0;
				G_XK = 0, G_YK = 0, G_ZK = 0;
				GNSS_POS_MODULE(geph, dg2, Njz, BX[Njz], BBY[Njz], BZ[Njz], &g_swj, &g_R, &G_XK, &G_YK, &G_ZK, jj, 1);//*****dg后面的参数为站号,Njz,(0,1,2,3,4……)为了配合dg【】中的号,最后一位整数1为GPS系统，2为BDS系统!!!!!!!!!!!!!;
				if (g_swj != 0 && g_R != 0)
				{
					Bgps_wj[Njz][Bn[Njz]] = g_swj;
					BGPS_SR[Njz][Bn[Njz]] = g_R;
					BBPC[Njz].GPC[Bn[Njz]] = g_R - g_swj;
					BBPC[Njz].G_PRN[Bn[Njz]] = dg2[Njz].prn[jj];
					Bgps_coor[Njz].X[Bn[Njz]] = G_XK;
					Bgps_coor[Njz].Y[Bn[Njz]] = G_YK;
					Bgps_coor[Njz].Z[Bn[Njz]] = G_ZK;
					//SUM_GPC[Njz]+=BBPC[Njz].GPC[Bn[Njz]];
					Bn[Njz]++;								        //Bn[Njz]为可利用GPS卫星数目	
				}
			}
			//MEAN_GPC[Njz]=SUM_GPC[Njz]/Bn[Njz];
			////for (int m=0;m<Bn[Njz];m++){BBPC[Njz].GPC[m]=BBPC[Njz].GPC[m]-MEAN_GPC[Njz];}//Bn[Njz]为可利用GPS卫星数目,从0开始算，所以小于Bn[Njz]
			for (int jj = Bgps_num[Njz] + Bglo_num[Njz]; jj < dg2[Njz].nsat; jj++)
			{
				b_swj = 0, b_R = 0;
				B_XK = 0, B_YK = 0, B_ZK = 0;
				GNSS_POS_MODULE(geph, dg2, Njz, BX[Njz], BBY[Njz], BZ[Njz], &b_swj, &b_R, &B_XK, &B_YK, &B_ZK, jj, 2);//dg后面的参数为站号,0,1,2,3,为了配合dg【】中的号，最后一位整数1为GPS系统，2为BDS系统;
				if (b_swj != 0 && b_R != 0)
				{
					Bbds_wj[Njz][Bp[Njz]] = b_swj;
					BBDS_SR[Njz][Bp[Njz]] = b_R;
					BBPC[Njz].CPC[Bp[Njz]] = b_R - b_swj;
					BBPC[Njz].C_PRN[Bp[Njz]] = dg2[Njz].prn[jj];
					Bbds_coor[Njz].X[Bp[Njz]] = B_XK;
					Bbds_coor[Njz].Y[Bp[Njz]] = B_YK;
					Bbds_coor[Njz].Z[Bp[Njz]] = B_ZK;
					//SUM_CPC[Njz]+=BBPC[Njz].CPC[Bp[Njz]];
					Bp[Njz]++;								//Bp[Njz]为可利用GPS卫星数目
				}
			}
			////MEAN_CPC[Njz]=SUM_CPC[Njz]/Bp[Njz];
			////MEAN_GCPC[Njz]=(SUM_GPC[Njz]+SUM_CPC[Njz])/(Bn[Njz]+Bp[Njz]);
			//for (int m=0;m<Bn[Njz];m++){BBPC[Njz].GPC[m]=BBPC[Njz].GPC[m]-MEAN_GPC[Njz];}
			//for (int m=0;m<Bp[Njz];m++){BBPC[Njz].CPC[m]=BBPC[Njz].CPC[m]-MEAN_GPC[Njz];}//Bn[Njz]为可利用GPS卫星数目,从0开始算，所以小于Bn[Njz]
		}
		BS_PR_CR BPC[20] = { 0 };

		int k[10]={0}, nn = 0, pp = 0;
		for ( k[1] = 0; k[1]<Bn[1]; k[1]++)						//主控站1GPS卫星数
		{
			for ( k[2] = 0; k[2]<Bn[2]; k[2]++)					//监测站2GPS卫星数
			{
				if (BBPC[1].G_PRN[k[1]] == BBPC[2].G_PRN[k[2]])
				{
					for ( k[3] = 0; k[3]<Bn[3]; k[3]++)			//监测站3GPS卫星数
					{
						if (BBPC[1].G_PRN[k[1]] == BBPC[3].G_PRN[k[3]])
						{
							for ( k[4] = 0; k[4]<Bn[4]; k[4]++)					//监测站4GPS卫星数
							{
								if (BBPC[1].G_PRN[k[1]] == BBPC[4].G_PRN[k[4]])
								{

									BPC[1].G_PRN[nn] = BBPC[1].G_PRN[k[1]];//反距离加权后的BPC除伪距改正项外，其他与主控站一致
									for(int mj=1;mj<5;mj++)
									{
										BPC[mj].GPC[nn] = BBPC[mj].GPC[k[mj]];
									}
									/*BPC[1].GPC[nn] = BBPC[1].GPC[k[1]];
									BPC[2].GPC[nn] = BBPC[2].GPC[k[2]];
									BPC[3].GPC[nn] = BBPC[3].GPC[k[3]];
									BPC[4].GPC[nn] = BBPC[4].GPC[k[4]];*/
									nn++;
									break;
								}
							}
							break;
						}
					}
					break;
				}
			}
		}
		for ( k[1] = 0; k[1]<Bp[1]; k[1]++)						//主控站1BDS卫星数
		{
			for ( k[2] = 0; k[2]<Bp[2]; k[2]++)					//监测站2BDS卫星数
			{
				if (BBPC[1].C_PRN[k[1]] == BBPC[2].C_PRN[k[2]])
				{
					for ( k[3] = 0; k[3]<Bp[3]; k[3]++)			//监测站3BDS卫星数
					{
						if (BBPC[1].C_PRN[k[1]] == BBPC[3].C_PRN[k[3]])
						{
							for ( k[4] = 0; k[4]<Bp[4]; k[4]++)					//监测站4BDS卫星数
							{
								if (BBPC[1].C_PRN[k[1]] == BBPC[4].C_PRN[k[4]])
								{

									BPC[1].C_PRN[pp] = BBPC[1].C_PRN[k[1]];//反距离加权后的BPC除伪距改正项外，其他与主控站一致
									for(int mj=1;mj<5;mj++)
									{
										BPC[mj].CPC[pp] = BBPC[mj].CPC[k[mj]];
									}
									/*BPC[1].CPC[nn] = BBPC[1].CPC[k[1]];
									BPC[2].CPC[nn] = BBPC[2].CPC[k[2]];
									BPC[3].CPC[nn] = BBPC[3].CPC[k[3]];
									BPC[4].CPC[nn] = BBPC[4].CPC[k[4]];*/

									pp++;
									break;

								}
							}
							break;
						}
					}
					break;
				}
			}
		}
		memset(Bn,0x00,sizeof(int)*20);
		memset(Bp,0x00,sizeof(int)*20);
		memset(BBPC,0x00,sizeof(BS_PR_CR)*20);
		for(int j=1;j<5;j++)
		{
			Bn[j] = nn;
			Bp[j] = pp;
			for(int i=0;i<nn;i++)
			{
				BBPC[j].G_PRN[i] = BPC[1].G_PRN[i];
				BBPC[j].GPC[i] = BPC[j].GPC[i];
			}
			for(int ii=0;ii<pp;ii++)
			{
				BBPC[j].C_PRN[ii] = BPC[1].C_PRN[ii];
				BBPC[j].CPC[ii] = BPC[j].CPC[ii];
			}
		}

		fprintf(BPC_fil, "%5d\n",int(dg0[0].tg.second));
		for (int njzz=1; njzz< NO_JZZ; njzz++)      //基准站个数Njzz，统计所有基准站各类卫星数目,河北现在共4个基准站1个流动站              
		{
			fprintf(BPC_fil, "BBPC%3d %5d  G:%3d  C:%3d\n", njzz,int(dg0[0].tg.second), Bn[njzz],Bp[njzz]);
			for (int u = 0; u < Bn[njzz]; u++)
				fprintf(BPC_fil, "BBPC%3d G%3d,%5d,%10.3f\n", njzz,BBPC[njzz].G_PRN[u],int(dg0[0].tg.second), BBPC[njzz].GPC[u]);//,%10.3f,%10.3f,Bgps_wj[njzz][u],BGPS_SR[njzz][u]
			for (int r = 0; r < Bp[njzz]; r++)
				fprintf(BPC_fil, "BBPC%3d C%3d,%5d,%10.3f\n", njzz,BBPC[njzz].C_PRN[r],int(dg0[0].tg.second), BBPC[njzz].CPC[r]);//,%10.3f,%10.3f,Bbds_wj[njzz][r],BBDS_SR[njzz][r]
		}

	}//开始那个if判断各站数据接收是否正确的判断结尾;
#endif
#pragma endregion
}

void CNDGNSS::Dist_GB(double GXYZ[],double BXYZ[], double &Distance)//求距离;
{
	//中心点坐标排列顺序是：从低纬到高纬，从西向东（与自转相同）;
	Distance=sqrt((BXYZ[0]-GXYZ[0])*(BXYZ[0]-GXYZ[0])+(BXYZ[1]-GXYZ[1])*(BXYZ[1]-GXYZ[1])+(BXYZ[2]-GXYZ[2])*(BXYZ[2]-GXYZ[2]));
	return;
}

void CNDGNSS::NWDGNSS_GRID_CENTER_PRODUCE(double LONGITUDE0,double DLONGITUDE,int NLONGITUDE,double LATITUDE0,double DLATITUDE,int NLATITUDE,double G_C_COORD[][6])//,double G_C_XYZ[][3]
{
	//中心点坐标排列顺序是：从低纬到高纬，从西向东（与自转相同）;
	/*double PI=3.141592653589793;*/
	for(int i=0;i<NLATITUDE;i++)
	{
		for(int j=0;j<NLONGITUDE;j++)
		{
			G_C_COORD[i*NLONGITUDE+j][0]=LATITUDE0+(i+0.5)*DLATITUDE;//网格中心点纬度B;
			G_C_COORD[i*NLONGITUDE+j][1]=LONGITUDE0+(j+0.5)*DLONGITUDE;//网格中心点经度L;
			G_C_COORD[i*NLONGITUDE+j][2]=0;//网格中心点高程;
			double B,L,H,x,y,z;
			B=G_C_COORD[i*NLONGITUDE+j][0]/180*PI;
			L=G_C_COORD[i*NLONGITUDE+j][1]/180*PI;
			H=0.0;
			BLHTOXYZ( B, L, H, x, y, z);
			G_C_COORD[i*NLONGITUDE+j][3]=x;
			G_C_COORD[i*NLONGITUDE+j][4]=y;
			G_C_COORD[i*NLONGITUDE+j][5]=z;
		}
	}
	return;
}
double CNDGNSS:: glorbit1(double t, double *x, const double *acc)
{
    double k1[6],k2[6],k3[6],k4[6],w[6];
    int i;
    
 //   deq(x,k1,acc); for (i=0;i<3;i++) w[i]=x[i]+x[i+3]*t/2.0+k1[i+3]*t*t/8.0;for (i=0;i<3;i++) w[i+3]=x[i+3]+k1[i+3]*t/2.0;
 //   deq(w,k2,acc); for (i=0;i<3;i++) w[i]=x[i]+x[i+3]*t/2.0+k2[i+3]*t*t/8.0;for (i=0;i<3;i++) w[i+3]=x[i+3]+k2[i+3]*t/2.0;
 //   deq(w,k3,acc); for (i=0;i<3;i++) w[i]=x[i]+x[i+3]*t    +k3[i+3]*t*t/2.0;for (i=0;i<3;i++) w[i+3]=x[i+3]+k3[i+3]*t;
 //   deq(w,k4,acc);
 //   for (i=0;i<3;i++)
	//{
	//	x[i]+=x[i+3]*t+t*t*(k1[i+3]+2.0*k2[i+3]+2.0*k3[i+3]+k4[i+3])/12.0;
	//    x[i+3]=x[i+3]+t*(k1[i+3]+2.0*k2[i+3]+2.0*k3[i+3]+k4[i+3])/6.0;
	//}
    deq(x,k1,acc); for (i=0;i<6;i++) w[i]=x[i]+k1[i]*t/2.0;
    deq(w,k2,acc); for (i=0;i<6;i++) w[i]=x[i]+k2[i]*t/2.0;
    deq(w,k3,acc); for (i=0;i<6;i++) w[i]=x[i]+k3[i]*t;
    deq(w,k4,acc);
    for (i=0;i<6;i++) x[i]+=(k1[i]+2.0*k2[i]+2.0*k3[i]+k4[i])*t/6.0;

	// for (i=0;i<3;i++) x[i]+=(k1[i+3]+2.0*k2[i]+2.0*k3[i]+k4[i])*t/6.0;
	return 0;
}
double CNDGNSS::Calsatpos_GLO(gtime_t te,gtime_t to,double pr,gtime_t &tim,double a[],double stxyz[],double svxyz[],double &t1)
{   
	//double TSTEP=10.0;            /* integration step glonass ephemeris (s) */
    double t,tt,x[6],tc=0;
    int i;
	double acc[3]={0};
    double svclk=0;
	double var;
	gtime_t time;	  

	/* transmission time by satellite clock */
	//
	//to=timeadd(to,stxyz[3]/299792458.0);

	//time=timeadd(to,-pr/299792458.0 );
	//tc=geph2clk(te,time,a);
	//time=timeadd(time,-tc);
	// t=timediff(time,te);
	t=timediff(to,te);
    if(fabs(t)>1800) return 1;
	 svclk=-a[2]+a[3]*t;

	t1=0;
	x[0]=a[5];        
	x[1]=a[9];	
	x[2]=a[13];
	x[3]=a[6];
	x[4]=a[10];
	x[5]=a[14];
	acc[0]=a[7];
	acc[1]=a[11];
	acc[2]=a[15];
    for (tt=t<0.0?-TSTEP:TSTEP;fabs(t)>1E-9;t-=tt) {
        if (fabs(t)<TSTEP) tt=t;
        glorbit1(tt,x,acc);
    }
    for (i=0;i<3;i++) svxyz[i]=x[i];
    
   /* var=SQR(ERREPH_GLO);*/
	//tim=time;
	tim=to;
	return svclk;
}
double CNDGNSS::GetSVpos_GLO(gtime_t te,gtime_t to,double pr,double a[],double &X0,double &Y0,double &Z0,double *XK,double *YK,double *ZK,double &tc)//(这一块是5个参数，第一个是接收机的周，第二个是接收机的秒，第三个是该卫星的28个参数，
{                                                                               //   第四个参数是测站的位置。第五个是卫星的位置)//最后一个参数一定要好好看看
	double	t,t0,dr[3],svclk,t1=0;
	double	OMEGADOT=7.292115e-5;
	double stxyz[3]={0},svxyz[3]={0};
	gtime_t tim,obstime;
	t=0.075;
	int xunhuan=0;
	stxyz[0]=X0;stxyz[1]=Y0;stxyz[2]=Z0;
	do
	{
		xunhuan++;
		if(xunhuan>20)
			return(svclk);
		t0=t;	
		//svclk=Calsatpos_GLO(te,to,pr,a,stxyz,svxyz,tc);
		obstime=timeadd(to,-t0);
		svclk=Calsatpos_GLO(te,obstime,pr,tim,a,stxyz,svxyz,t1);
		if(svclk>90.0)
			return(svclk);
		svxyz[0]+=0.634;
		svxyz[1]-=0.003;
		svxyz[2]+=1.075;
		dr[0]=stxyz[0]-svxyz[0];
		dr[1]=stxyz[1]-svxyz[1];
		dr[2]=stxyz[2]-svxyz[2];
		t=sqrt(dr[0]*dr[0]+dr[1]*dr[1]+dr[2]*dr[2])/299792458.0;
	}while(fabs(t-t0)>1e-9);//使其传播时间达到收敛（这一块是一定要考虑的就是传播时间要收敛）
	//知道这个时间之后传播时间之后就可以进行
	tc=t;
	svxyz[0]+=OMEGADOT*svxyz[1]*t;//地球自转改正
	svxyz[1]-=OMEGADOT*svxyz[0]*t;
	*XK=svxyz[0];*YK=svxyz[1];*ZK=svxyz[2];
	return(svclk);
}
double CNDGNSS::CalcuateSVpos(long week,double second,double a[],double svxyz[])//这个是求卫星轨道的信息函数   求的是卫星的瞬时坐标
{
	double	span,svclk;
	double	dat_n0,n,Mk,Ek,Vk,Qk,zU,zR,zI,Uk,Rk,Ik,xk,yk;
	double	omgk,Tr;
	double	temp,temp1,temp2;

	span=(week-a[21])*604800.0+second-a[11];// 这里的span=t-toe  这个判读就是来看看是不是在两个小时以内//它是在这一块来判断是不是两个小时以内的
	if(span>7200.3 || span<-7200.3)
	{
		cout<<"***WARNING: no ephemeris or too old-GPS!"<<endl;
		return(99.0);
	}
	//开始计算卫星的轨道
	dat_n0=sqrt(3.986005e+14)/(a[10]*a[10]*a[10]);//计算卫星运动在参考时刻toe时刻的平均角速度
	n=dat_n0+a[5];//观测时刻的平均角速度
	Mk=a[6]+n*span;//计算观测瞬间卫星的平近点角
	Ek=Mk;
	do
	{
		temp=Ek;
		Ek=Mk+a[8]*sin(Ek);
	}while(fabs(Ek-temp)>1e-9);//迭代求出偏近点角
	temp1=sqrt(1-a[8]*a[8])*sin(Ek);
	temp2=cos(Ek)-a[8];

	Vk=atan2(temp1,temp2);//计算出的真近点角vk
	Qk=Vk+a[17];//计算出的升交角距

	zU=a[7]*cos(2.0*Qk)+a[9]*sin(2.0*Qk);//计算的各项的摄动改正
	zR=a[16]*cos(2.0*Qk)+a[4]*sin(2.0*Qk);
	zI=a[12]*cos(2.0*Qk)+a[14]*sin(2.0*Qk);

	Uk=Qk+zU;
	Rk=a[10]*a[10]*(1-a[8]*cos(Ek))+zR;//卫星的向经 及其改正
	Ik=a[15]+zI+a[19]*span;
	xk=Rk*cos(Uk);
	yk=Rk*sin(Uk);//求出的卫星在轨道平面坐标系中的位置
	omgk=a[13]+(a[18]-7.2921151467e-5)*span-7.2921151467e-5*a[11];
	svxyz[0]=xk*cos(omgk)-yk*cos(Ik)*sin(omgk);
	svxyz[1]=xk*sin(omgk)+yk*cos(Ik)*cos(omgk);
	svxyz[2]=yk*sin(Ik);
	Tr=-4.442807633e-10*a[8]*a[10]*sin(Ek);//这个是相对论效应的影响
	svclk=(a[0]+a[1]*span+a[2]*span*span+Tr)-a[25];//这一块要好好看看这一块是求卫星钟的钟差*****加了那个相对论效应减去了TGD就是a[25]元素
	return(svclk);
}
double CNDGNSS::GetSVpos(long week,double second,double a[],double &X0,double &Y0,double &Z0,double *XK,double *YK,double *ZK)//(这一块是5个参数，第一个是接收机的周，第二个是接收机的秒，第三个是该卫星的28个参数，
{                                                                               //   第四个参数是测站的位置。第五个是卫星的位置)//最后一个参数一定要好好看看
	double	t,t0,dr[3],svclk;
	double	OMEGADOT=7.2921151467e-5;
	double stxyz[3]={0},svxyz[3]={0};
	stxyz[0]=X0;stxyz[1]=Y0;stxyz[2]=Z0;
	int xunhuan=0;
	t=0.075;
	do
	{
		xunhuan++;
		if(xunhuan>20)
			return(svclk);
		t0=t;
		svclk=CalcuateSVpos(week,second-t0,a,svxyz);//(根据不同的时间计算出卫星的坐标下面还要用到卫星的坐标)参数(1.信号发射时间的周和秒3.a表示的是广播星历4.卫星的坐标)
		if(svclk>90.0)
			return(svclk);
		dr[0]=stxyz[0]-svxyz[0];
		dr[1]=stxyz[1]-svxyz[1];
		dr[2]=stxyz[2]-svxyz[2];
		t=sqrt(dr[0]*dr[0]+dr[1]*dr[1]+dr[2]*dr[2])/299792458.0;
	}while(fabs(t-t0)>1e-9);//使其传播时间达到收敛（这一块是一定要考虑的就是传播时间要收敛）
	svxyz[0]+=OMEGADOT*svxyz[1]*t;//地球自转改正
	svxyz[1]-=OMEGADOT*svxyz[0]*t;
	*XK=svxyz[0];*YK=svxyz[1];*ZK=svxyz[2];
	return(svclk);
}
double CNDGNSS::GetSVpos_BDS(long week,double second,double a[],double &X0,double &Y0,double &Z0,double *XK,double *YK,double *ZK)//(这一块是5个参数，第一个是接收机的周，第二个是接收机的秒，第三个是该卫星的28个参数，
{                                                                               //   第四个参数是测站的位置。第五个是卫星的位置)//最后一个参数一定要好好看看
	double	t,t0,dr[3],svclk;
	double	OMEGADOT=7.2921151467e-5;
	double stxyz[3]={0},svxyz[3]={0};
	stxyz[0]=X0;stxyz[1]=Y0;stxyz[2]=Z0;
	int xunhuan=0;
	t=0.075;
	do
	{
		xunhuan++;
		if(xunhuan>20)
			return(svclk);
		t0=t;
		svclk=Calsatpos_BDS(week,second-t0,a,svxyz);//(根据不同的时间计算出卫星的坐标下面还要用到卫星的坐标)参数(1.信号发射时间的周和秒3.a表示的是广播星历4.卫星的坐标)
		if(svclk>90.0)
			return(svclk);
		dr[0]=stxyz[0]-svxyz[0];
		dr[1]=stxyz[1]-svxyz[1];
		dr[2]=stxyz[2]-svxyz[2];
		t=sqrt(dr[0]*dr[0]+dr[1]*dr[1]+dr[2]*dr[2])/299792458.0;
	}while(fabs(t-t0)>1e-9);//使其传播时间达到收敛（这一块是一定要考虑的就是传播时间要收敛）
	svxyz[0]+=OMEGADOT*svxyz[1]*t;//地球自转改正
	svxyz[1]-=OMEGADOT*svxyz[0]*t;
	*XK=svxyz[0];*YK=svxyz[1];*ZK=svxyz[2];
	return(svclk);
}
double CNDGNSS::Calsatpos_BDS(long week,double second,double a[],double svxyz[])
	// Calculate current IGSO or MEO satellite position of BDS. 
	// 2012-09 created by Huizhong Zhu.
	// week:BDS week; second: second of week; a:eph; svxyz: satellite position.
{
	double	span,svclk;
	double	dat_n0,n,Mk,Ek,Vk,Qk,zU,zR,zI,Uk,Rk,Ik,xk,yk;
	double	omgk,Tr;
	double	temp,temp1,temp2;

	double	GM=3.986004418e+14;	// m**3/s**2
	double	OMEGADOT=7.292115e-5;	// rad/s
	double	F=1.0/298.257222101;

	span=(week-a[21])*604800.0+second-a[11];
	if(span>3610 || span<-3610)
	{
		printf("***WARNING: no ephemeris or too old-BD!\n");
		return(99.0);
	}

	dat_n0=sqrt(GM)/(a[10]*a[10]*a[10]);
	n=dat_n0+a[5];
	Mk=a[6]+n*span;
	Ek=Mk;
	do
	{
		temp=Ek;
		Ek=Mk+a[8]*sin(Ek);
	}while(fabs(Ek-temp)>1e-9);
	temp1=sqrt(1-a[8]*a[8])*sin(Ek);
	temp2=cos(Ek)-a[8];

	Vk=atan2(temp1,temp2);
	Qk=Vk+a[17];

	zU=a[7]*cos(2.0*Qk)+a[9]*sin(2.0*Qk);
	zR=a[16]*cos(2.0*Qk)+a[4]*sin(2.0*Qk);
	zI=a[12]*cos(2.0*Qk)+a[14]*sin(2.0*Qk);

	Uk=Qk+zU;
	Rk=a[10]*a[10]*(1-a[8]*cos(Ek))+zR;
	Ik=a[15]+zI+a[19]*span;
	xk=Rk*cos(Uk);
	yk=Rk*sin(Uk);
	omgk=a[13]+(a[18]-OMEGADOT)*span-OMEGADOT*a[11];
	svxyz[0]=xk*cos(omgk)-yk*cos(Ik)*sin(omgk);
	svxyz[1]=xk*sin(omgk)+yk*cos(Ik)*cos(omgk);
	svxyz[2]=yk*sin(Ik);
	// Calculate sv clock bias.
	Tr=-4.442807633e-10*a[8]*a[10]*sin(Ek);
	svclk=(a[0]+a[1]*span+a[2]*span*span+Tr)-a[25];

	return(svclk);
}
double CNDGNSS::GetSVpos_GEO(long week,double second,double a[],double &X0,double &Y0,double &Z0,double *XK,double *YK,double *ZK)//(这一块是5个参数，第一个是接收机的周，第二个是接收机的秒，第三个是该卫星的28个参数，
{                                                                               //   第四个参数是测站的位置。第五个是卫星的位置)//最后一个参数一定要好好看看
	double	t,t0,dr[3],svclk;
	double	OMEGADOT=7.2921151467e-5;
	double stxyz[3]={0},svxyz[3]={0};
	stxyz[0]=X0;stxyz[1]=Y0;stxyz[2]=Z0;
	t=0.075;
	int xunhuan=0;
	do
	{
		xunhuan++;
		if(xunhuan>20)
			return(svclk);
		t0=t;
		svclk=Calsatpos_GEO(week,second-t0,a,svxyz);//(根据不同的时间计算出卫星的坐标下面还要用到卫星的坐标)参数(1.信号发射时间的周和秒3.a表示的是广播星历4.卫星的坐标)
		if(svclk>90.0)
			return(svclk);
		dr[0]=stxyz[0]-svxyz[0];
		dr[1]=stxyz[1]-svxyz[1];
		dr[2]=stxyz[2]-svxyz[2];
		t=sqrt(dr[0]*dr[0]+dr[1]*dr[1]+dr[2]*dr[2])/299792458.0;
	}while(fabs(t-t0)>1e-9);//使其传播时间达到收敛（这一块是一定要考虑的就是传播时间要收敛）
	svxyz[0]+=OMEGADOT*svxyz[1]*t;//地球自转改正
	svxyz[1]-=OMEGADOT*svxyz[0]*t;
	*XK=svxyz[0];*YK=svxyz[1];*ZK=svxyz[2];
	return(svclk);
}
double CNDGNSS::Calsatpos_GEO(long week,double second,double a[],double svxyz[])//这几个是计算北斗GEO卫星的坐标的。
	// Calculate current GEO satellite position of BDS. 
	// 2012-09 created by Huizhong Zhu.
	// week:BDS week; second: second of week; a:eph; svxyz: satellite position.
{
	double	span,svclk;
	double	dat_n0,n,Mk,Ek,Vk,Qk,zU,zR,zI,Uk,Rk,Ik,xk,yk;
	double	omgk,Tr;
	double	temp,temp1,temp2;

	double	GM=3.986004418e+14;	// m**3/s**2
	double	OMEGADOT=7.292115e-5;	// rad/s
	double	F=1.0/298.257222101;

	//beidou
	double	phix,phiz;
	double	Rx[9],Rz[9],R[9],xyz[3];

	span=(week-a[21])*604800.0+second-a[11];
	if(span>3610 || span<-3610)
	{
		printf("***WARNING: no ephemeris or too old!-GEO\n");
		return(99.0);
	}


	dat_n0=sqrt(GM)/(a[10]*a[10]*a[10]);
	n=dat_n0+a[5];
	Mk=a[6]+n*span;
	Ek=Mk;
	do
	{
		temp=Ek;
		Ek=Mk+a[8]*sin(Ek);
	}while(fabs(Ek-temp)>1e-9);
	temp1=sqrt(1-a[8]*a[8])*sin(Ek);
	temp2=cos(Ek)-a[8];

	Vk=atan2(temp1,temp2);
	Qk=Vk+a[17];

	zU=a[7]*cos(2.0*Qk)+a[9]*sin(2.0*Qk);
	zR=a[16]*cos(2.0*Qk)+a[4]*sin(2.0*Qk);
	zI=a[12]*cos(2.0*Qk)+a[14]*sin(2.0*Qk);

	Uk=Qk+zU;
	Rk=a[10]*a[10]*(1-a[8]*cos(Ek))+zR;
	Ik=a[15]+zI+a[19]*span;
	xk=Rk*cos(Uk);
	yk=Rk*sin(Uk);
	omgk=a[13]+a[18]*span-OMEGADOT*a[11];	//*******
	xyz[0]=xk*cos(omgk)-yk*cos(Ik)*sin(omgk);
	xyz[1]=xk*sin(omgk)+yk*cos(Ik)*cos(omgk);
	xyz[2]=yk*sin(Ik);
	// BeiDou
	phix=(-5.0)*(atan(1.0)*4.0)/180.0;
	phiz=OMEGADOT*span;
	temp1=sin(phix);
	temp2=cos(phix);
	Rx[0]=1.0;
	Rx[1]=0.0;
	Rx[2]=0.0;
	Rx[3]=0.0;
	Rx[4]=temp2;
	Rx[5]=temp1;
	Rx[6]=0.0;
	Rx[7]=-temp1;
	Rx[8]=temp2;
	temp1=sin(phiz);
	temp2=cos(phiz);
	Rz[0]=temp2;
	Rz[1]=temp1;
	Rz[2]=0.0;
	Rz[3]=-temp1;
	Rz[4]=temp2;
	Rz[5]=0.0;
	Rz[6]=0.0;
	Rz[7]=0.0;
	Rz[8]=1.0;
	MatrixMult(Rz,Rx,R,3,3,3);
	MatrixMult(R,xyz,svxyz,3,3,1);


	//Allmatrixmultiply(3,3,3,Rz,Rx,0,R);
	//Allmatrixmultiply(3,3,1,R,xyz,0,svxyz);

	// Calculate sv clock bias.
	Tr=-4.442807633e-10*a[8]*a[10]*sin(Ek);
	svclk=(a[0]+a[1]*span+a[2]*span*span+Tr)-a[25];


	return(svclk);
}
/*矩阵相乘 a是m行n列 b是n行k列  c为m行k列*/
void CNDGNSS::MatrixMult(double a[],double b[],double c[],int m,int n,int k)
{
	int i,j,l;
	for(i=0;i<m;i++)
		for(j=0;j<k;j++)
		{
			c[i*k+j]=0.0;
			for(l=0;l<n;l++)
			{
				c[i*k+j]=c[i*k+j]+a[i*n+l]*b[l*k+j];
			}
		}
		return;
}
double CNDGNSS::Produce_ReferenceStation_Corrcetion_gps_bds_glo(DATG dg0,GEPH geph[],IOFH ih0,BS_PR_CR_JH &BBPC)
{

	memset(&BBPC,0x00,sizeof(BBPC));
	//int Bn[30]={0}, Bp[30]={0};
	DATG dg2[1];
	IOFH ih2[1];
	memset(dg2,0x00,sizeof(dg2));
	memset(ih2,0x00,sizeof(ih2));
	dg2[0] = dg0;
	ih2[0] = ih0;

	//int		NN = 0, PP = 0, QQ = 0;						//可利用GPS,BDS,GLONASS卫星数,这里再一次定义是为了将其输出;
	//double	GDOP_raim = 0, PDOP_raim = 0, GDOP1 = 0, PDOP1 = 0, GDOP2 = 0, PDOP2 = 0;

	/************▼基准站改正信息生成▼↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/

	int		Bgps_num, Bbds_num, Bglo_num;		//基准站当前历元GPS、BDS可见卫星数
	memset(&Bgps_num,0,sizeof(Bgps_num));
	memset(&Bbds_num,0,sizeof(Bbds_num));
	memset(&Bglo_num,0,sizeof(Bglo_num));

	//▼▼▼基准站▼▼▼;						
	GPST T_BBPC={0};
	T_BBPC=dg2[0].tg;

	sp		gps_coor,bds_coor,glo_coor;			//卫星坐标_结构体
	memset(&gps_coor,0x00,sizeof(gps_coor));
	memset(&bds_coor,0x00,sizeof(bds_coor));
	memset(&glo_coor,0x00,sizeof(glo_coor));
	double	GDOP=0.0,PDOP=0.0,RMS=0.0,X0=0.0,Y0=0.0,Z0=0.0,delt=0.0;
	int final_N=0,final_P=0,jinxingcuchatichu=0,xhyz=0,out_biaozhi=0;	
	rp rcoor0={0};
	if (T_BBPC.second!=dg2[0].tg.second) return 0;
	BBPC.tg=T_BBPC;//记录基准站GPST
	BBPC.BX = ih2[0].xyz[0];
	BBPC.BY = ih2[0].xyz[1];
	BBPC.BZ = ih2[0].xyz[2];
	rcoor0.X=BBPC.BX;
	rcoor0.Y=BBPC.BY;
	rcoor0.Z=BBPC.BZ;
	double rep[3]={0.0},reps[3]={0.0};
	double xyzt[3]={0};
	do 
	{
		if(xhyz>10) 
		{
			//TraceWarn(_T("prc -- xhyz=%2d"),xhyz);
			break;
		}
		delt=0.0;													//计算位置坐标，循环置0;
		BBPC.G_num=0;
		BBPC.C_num=0;
		BBPC.R_num=0;
		int		g_PRN[32]={0},b_PRN[32]={0},glo_PRN[32]={0};
		double gps_wj_end[32]={0},GPS_SR_end[32]={0};
		double bds_wj_end[32]={0},BDS_SR_end[32]={0};
		double glo_wj_end[32]={0},GLO_SR_end[32]={0};
		double glo_wj[32]={0},GLO_SR[32]={0};
		double	G_XK=0,G_YK=0,G_ZK=0,	B_XK=0,B_YK=0,B_ZK=0,	R_XK=0,R_YK=0,R_ZK=0;
		int		NN=0,PP=0,QQ=0;										//可利用GPS，BDS，GLONASS卫星数，这里再一次定义是为了将其输出;
		int		totle_sat=0;
		X0=rcoor0.X;
		Y0=rcoor0.Y;
		Z0=rcoor0.Z;
		rep[0] = reps[0];
		rep[1] = reps[1];
		rep[2] = reps[2];
		for (int jj = 0; jj < dg2[0].nsat; jj++)
		{
			if (dg2[0].prn[jj] >= 1 &&dg2[0].prn[jj] < 33)//gps
			{
				double g_swj = 0, g_R = 0;
				G_XK = 0, G_YK = 0, G_ZK = 0;
				GNSS_POS_MODULE(geph, dg2, 0, X0, Y0, Z0, &g_swj, &g_R, &G_XK, &G_YK, &G_ZK, jj, 1);//*****dg后面的参数为站号,Njz,(0,1,2,3,4……)为了配合dg【】中的号,最后一位整数1为GPS系统，2为BDS系统!!!!!!!!!!!!!;
				if (g_swj != 0 && g_R != 0)
				{
					/*Bgps_wj[Njz][Bn[Njz]] = g_swj;
					BGPS_SR[Njz][Bn[Njz]] = g_R;*/
					if (xhyz==0)
					{
						BBPC.GPC[BBPC.G_num] = g_R - g_swj;
						BBPC.G_PRN[BBPC.G_num] = dg2[0].prn[jj];
					}
					/*Bgps_coor[Njz].X[Bn[Njz]] = G_XK;
					Bgps_coor[Njz].Y[Bn[Njz]] = G_YK;
					Bgps_coor[Njz].Z[Bn[Njz]] = G_ZK;*/
					//SUM_GPC[Njz]+=BBPC[Njz].GPC[Bn[Njz]];
					//Bn[Njz]++;								        //Bn[Njz]为可利用GPS卫星数目	
					gps_coor.X[BBPC.G_num]		=G_XK;                   //为求接收机钟差，保留卫星坐标，卫星伪距，卫地几何距离20150819;
					gps_coor.Y[BBPC.G_num]		=G_YK;
					gps_coor.Z[BBPC.G_num]		=G_ZK;
					gps_wj_end[BBPC.G_num]     =g_swj;
					GPS_SR_end[BBPC.G_num]		=g_R;
					g_PRN[BBPC.G_num]		=dg2[0].prn[jj];
					BBPC.G_num++;
				}
			}

			//if (dg2[0].prn[jj] >= 1 &&dg2[0].prn[jj] < 33)//gps
			//{
			//	double g_swj = 0, g_R = 0;
			//	G_XK = 0, G_YK = 0, G_ZK = 0;
			//	int prn_satellite = dg2[0].prn[jj];
			//	if (geph[prn_satellite].a[24] == 1)//卫星不健康
			//		continue;
			//	double svclk=GetSVpos(dg2[0].tg.week,dg2[0].tg.second,geph[prn_satellite].a,X0,Y0,Z0,&G_XK, &G_YK, &G_ZK); 
			//	if(svclk > 10.0)
			//		continue;
			//	g_R=sqrt(pow(G_XK-X0,2)+pow(G_YK-Y0,2)+pow(G_ZK-Z0,2));//卫地距
			//	double rs[3]={0.0},rr[3]={0.0},r2suv[3]={0},pos[3]={0},azel[2]={0};
			//	double EL = 0;
			//	rs[0]=G_XK;
			//	rs[1]=G_YK;
			//	rs[2]=G_ZK;
			//	rr[0]=X0;
			//	rr[1]=Y0;
			//	rr[2]=Z0;
			//	geodist(rs,rr,r2suv);
			//	ecef2pos(rr,pos);
			//	EL=satazel(pos,r2suv,azel);
			//	if(fabs(EL*R2D)>15.0)//判断卫星高度角
			//	{
			//		g_swj = dg2[0].data[jj][0] + svclk*299792458.0 ;//伪距
			//	}
			//	else							//高度角为10度((PI/18=0.17453292519943))，小于10的卫星舍去  15度 PI/12=0.2617993877991
			//	{
			//		g_R = 0;
			//		g_swj = 0;
			//		G_XK = 0;
			//		G_YK = 0;
			//		G_ZK = 0;
			//	}
			//	if (g_swj != 0 && g_R != 0)
			//	{
			//		if (xhyz==0)
			//		{
			//			BBPC.GPC[BBPC.G_num] = g_R - g_swj;
			//			BBPC.G_PRN[BBPC.G_num] = dg2[0].prn[jj];
			//		}
			//		gps_coor.X[BBPC.G_num]		=G_XK;                   //为求接收机钟差，保留卫星坐标，卫星伪距，卫地几何距离20150819;
			//		gps_coor.Y[BBPC.G_num]		=G_YK;
			//		gps_coor.Z[BBPC.G_num]		=G_ZK;
			//		gps_wj_end[BBPC.G_num]     =g_swj;
			//		GPS_SR_end[BBPC.G_num]		=g_R;
			//		g_PRN[BBPC.G_num]		=dg2[0].prn[jj];
			//		BBPC.G_num++;
			//	}
			//}

			if (dg2[0].prn[jj] >= 33 && dg2[0].prn[jj] < 57)//glonass，张静云版本，周万振加
			{
				double glo_swj = 0, glo_R = 0;
				R_XK = 0, R_YK = 0, R_ZK = 0;
				int prn_satellite = dg2[0].prn[jj];
				if (geph[prn_satellite].a[8] == 1)//卫星不健康
					continue;
				if (geph[prn_satellite].a[5] == 0.0||geph[prn_satellite].a[9] == 0.0||geph[prn_satellite].a[13] == 0.0)
					continue;
				double  tc=0,tc1=0;
				gtime_t glo_t;
				glo_t.time=geph[prn_satellite].a[0];
				glo_t.sec =geph[prn_satellite].a[1];
				gtime_t glo_ot = gpst2time(dg2[0].tg.week, dg2[0].tg.second);
				double svclk=GetSVpos_GLO(glo_t,glo_ot,dg2[0].data[jj][0],geph[prn_satellite].a,X0,Y0,Z0,&R_XK, &R_YK, &R_ZK,tc);
				if(svclk > 10.0)
					continue;
				glo_R=sqrt(pow(R_XK-X0,2)+pow(R_YK-Y0,2)+pow(R_ZK-Z0,2));//卫地距
				double rs[3]={0.0},rr[3]={0.0},r2suv[3]={0},pos[3]={0},azel[2]={0};
				double EL = 0;
				rs[0]=R_XK;
				rs[1]=R_YK;
				rs[2]=R_ZK;
				rr[0]=X0;
				rr[1]=Y0;
				rr[2]=Z0;
				geodist(rs,rr,r2suv);
				ecef2pos(rr,pos);
				EL=satazel(pos,r2suv,azel);
				if(fabs(EL*R2D)>10.0)//判断卫星高度角
				{
					glo_swj = dg2[0].data[jj][0] + svclk*299792458.0 ;//伪距
				}
				else							//高度角为10度((PI/18=0.17453292519943))，小于10的卫星舍去  15度 PI/12=0.2617993877991
				{
					glo_R = 0;
					glo_swj = 0;
					R_XK = 0;
					R_YK = 0;
					R_ZK = 0;
				}
				if (glo_swj != 0 && glo_R != 0)
				{
					if (xhyz==0)
					{
						BBPC.RPC[BBPC.R_num] = glo_R - glo_swj;
						BBPC.R_PRN[BBPC.R_num] = dg2[0].prn[jj];
					}
					glo_coor.X[BBPC.R_num]		=R_XK;                   //为求接收机钟差，保留卫星坐标，卫星伪距，卫地几何距离20150819;
					glo_coor.Y[BBPC.R_num]		=R_YK;
					glo_coor.Z[BBPC.R_num]		=R_ZK;
					glo_wj_end[BBPC.R_num]      =glo_swj;
					GLO_SR_end[BBPC.R_num]		=glo_R;
					glo_PRN[BBPC.R_num]		    =dg2[0].prn[jj];
					BBPC.R_num++;
				}
			}

			//if (dg2[0].prn[jj] >= 33 && dg2[0].prn[jj] < 57)//glonass，李鹤峰版本，周万振加
			//{
			//	double glo_swj = 0, glo_R = 0;
			//	R_XK = 0, R_YK = 0, R_ZK = 0;
			//	double rs[6];
			//	memset(rs,0x00,sizeof(rs));
			//	GLO_POS_MODULE(geph,dg2,0,X0,Y0,Z0,&glo_swj,&glo_R,&R_XK,&R_YK,&R_ZK,jj);
			//	if (glo_swj != 0 && glo_R != 0)
			//	{
			//		if (xhyz==0)
			//		{
			//			BBPC.RPC[BBPC.R_num] = glo_R - glo_swj;
			//			BBPC.R_PRN[BBPC.R_num] = dg2[0].prn[jj];
			//		}
			//		glo_coor.X[BBPC.R_num]		=R_XK;                   //为求接收机钟差，保留卫星坐标，卫星伪距，卫地几何距离20150819;
			//		glo_coor.Y[BBPC.R_num]		=R_YK;
			//		glo_coor.Z[BBPC.R_num]		=R_ZK;
			//		glo_wj_end[BBPC.R_num]      =glo_swj;
			//		GLO_SR_end[BBPC.R_num]		=glo_R;
			//		glo_PRN[BBPC.R_num]		    =dg2[0].prn[jj];
			//		BBPC.R_num++;
			//	}
			//}

			//if (dg2[0].prn[jj] >= 33 && dg2[0].prn[jj] < 57)//glonass，周万振版本，周万振加
			//{
			//	double glo_swj = 0, glo_R = 0;
			//	double rs[6];
			//	memset(rs,0x00,sizeof(rs));
			//	GLONASS_POS_MODULE(geph,dg2,0,X0,Y0,Z0,&glo_swj,&glo_R,rs,jj);//glonass
			//	if (glo_swj != 0 && glo_R != 0)
			//	{
			//		if (xhyz==0)
			//		{
			//			BBPC.RPC[BBPC.R_num] = glo_R - glo_swj;
			//			BBPC.R_PRN[BBPC.R_num] = dg2[0].prn[jj];
			//		}
			//		glo_coor.X[BBPC.R_num]		=rs[0];                   //为求接收机钟差，保留卫星坐标，卫星伪距，卫地几何距离20150819;
			//		glo_coor.Y[BBPC.R_num]		=rs[1];
			//		glo_coor.Z[BBPC.R_num]		=rs[2];
			//		glo_wj_end[BBPC.R_num]      =glo_swj;
			//		GLO_SR_end[BBPC.R_num]		=glo_R;
			//		glo_PRN[BBPC.R_num]		    =dg2[0].prn[jj];
			//		BBPC.R_num++;
			//	}
			//}

			//if (dg2[0].prn[jj] >= 161 && dg2[0].prn[jj] < 181)
			//{
			//	double b_swj = 0, b_R = 0;
			//	B_XK = 0, B_YK = 0, B_ZK = 0;
			//	int prn_satellite = dg2[0].prn[jj];
			//	if (geph[prn_satellite].a[24] == 1)//卫星不健康
			//		continue;
			//	double svclk=0.0;
			//	if(prn_satellite>165)
			//	{
			//		svclk=GetSVpos_BDS(dg2[0].tg.week,dg2[0].tg.second-14,geph[prn_satellite].a,X0,Y0,Z0,&B_XK,&B_YK, &B_ZK); 
			//		if(svclk > 10.0)
			//			continue;
			//	}
			//	else if(prn_satellite<=165)
			//	{
			//		svclk=GetSVpos_GEO(dg2[0].tg.week,dg2[0].tg.second-14,geph[prn_satellite].a,X0,Y0,Z0,&B_XK,&B_YK, &B_ZK);
			//		if(svclk > 10.0)
			//			continue;
			//	}
			//	b_R=sqrt(pow(B_XK-X0,2)+pow(B_YK-Y0,2)+pow(B_ZK-Z0,2));//卫地距
			//	double rs[3]={0.0},rr[3]={0.0},r2suv[3]={0},pos[3]={0},azel[2]={0};
			//	double EL = 0;
			//	rs[0]=B_XK;
			//	rs[1]=B_YK;
			//	rs[2]=B_ZK;
			//	rr[0]=X0;
			//	rr[1]=Y0;
			//	rr[2]=Z0;
			//	geodist(rs,rr,r2suv);
			//	ecef2pos(rr,pos);
			//	EL=satazel(pos,r2suv,azel);
			//	if(fabs(EL*R2D)>15.0)//判断卫星高度角
			//	{
			//		b_swj = dg2[0].data[jj][0] + svclk*299792458.0 ;//伪距
			//	}
			//	else							//高度角为10度((PI/18=0.17453292519943))，小于10的卫星舍去  15度 PI/12=0.2617993877991
			//	{
			//		b_R = 0;
			//		b_swj = 0;
			//		B_XK = 0;
			//		B_YK = 0;
			//		B_ZK = 0;
			//	}
			//	if (b_swj != 0 && b_R != 0)
			//	{
			//		if (xhyz==0)
			//		{
			//			BBPC.CPC[BBPC.C_num] = b_R - b_swj;
			//			BBPC.C_PRN[BBPC.C_num] = dg2[0].prn[jj];
			//		}
			//		bds_coor.X[BBPC.C_num]		=B_XK;                   //为求接收机钟差，保留卫星坐标，卫星伪距，卫地几何距离20150819;
			//		bds_coor.Y[BBPC.C_num]		=B_YK;
			//		bds_coor.Z[BBPC.C_num]		=B_ZK;
			//		bds_wj_end[BBPC.C_num]     =b_swj;
			//		BDS_SR_end[BBPC.C_num]		=b_R;
			//		b_PRN[BBPC.C_num]		=dg2[0].prn[jj];
			//		BBPC.C_num++;								//Bp[Njz]为可利用GPS卫星数目
			//	}
			//}

			if (dg2[0].prn[jj] >= 161 && dg2[0].prn[jj] < 181)
			{
				double b_swj = 0, b_R = 0;
				B_XK = 0, B_YK = 0, B_ZK = 0;
				GNSS_POS_MODULE(geph, dg2, 0, X0, Y0, Z0, &b_swj, &b_R, &B_XK, &B_YK, &B_ZK, jj, 2);//dg后面的参数为站号,0,1,2,3,为了配合dg【】中的号，最后一位整数1为GPS系统，2为BDS系统;
				if (b_swj != 0 && b_R != 0)
				{
					/*Bbds_wj[Njz][Bp[Njz]] = b_swj;
					BBDS_SR[Njz][Bp[Njz]] = b_R;*/
					if (xhyz==0)
					{
						BBPC.CPC[BBPC.C_num] = b_R - b_swj;
						BBPC.C_PRN[BBPC.C_num] = dg2[0].prn[jj];
					}
					/*Bbds_coor[Njz].X[Bp[Njz]] = B_XK;
					Bbds_coor[Njz].Y[Bp[Njz]] = B_YK;
					Bbds_coor[Njz].Z[Bp[Njz]] = B_ZK;*/
					//SUM_CPC[Njz]+=BBPC[Njz].CPC[Bp[Njz]];
					bds_coor.X[BBPC.C_num]		=B_XK;                   //为求接收机钟差，保留卫星坐标，卫星伪距，卫地几何距离20150819;
					bds_coor.Y[BBPC.C_num]		=B_YK;
					bds_coor.Z[BBPC.C_num]		=B_ZK;
					bds_wj_end[BBPC.C_num]     =b_swj;
					BDS_SR_end[BBPC.C_num]		=b_R;
					b_PRN[BBPC.C_num]		=dg2[0].prn[jj];
					BBPC.C_num++;								//Bp[Njz]为可利用GPS卫星数目
				}
			}

		}

		NN=BBPC.G_num;
		PP=BBPC.C_num;
		QQ=BBPC.R_num;
		totle_sat=NN+PP+QQ;

		if(NN>0&&PP>0&&QQ>0&&totle_sat>6)	//3系统时，为了防止和星历相同时刻时，有单个系统的星为0时，无法解算，程序无法进行，大于6时，RMS才有值20150701,有单个系统的星为0时，可以解算;
		{
			gps_bds_glo_coor(&rcoor0,gps_coor,gps_wj_end,GPS_SR_end,bds_coor,bds_wj_end,BDS_SR_end,glo_coor,glo_wj_end,GLO_SR_end,totle_sat,NN,PP,QQ,&GDOP,&PDOP,T_BBPC.second);//计算接收机坐标,返回位置的改正数rcoor.X、rcoor.Y、rcoor.Z;

			if(rcoor0.X==0&&rcoor0.Y==0&&rcoor0.Z==0)//不能循环太多，比如循环39次，这里的rcoor.X==0&&rcoor.Y==0&&rcoor.Z==0，但是是正确的
			{
				rcoor0.P1=0;
				rcoor0.P2=0;
				rcoor0.P3=0;
				break;
			}
			else
			{

				rcoor0.X=rcoor0.X+X0;	//新的接收机坐标=改正数+初值，下面判断，如果delt>0.001的话，返回do，将rcoor.X重新作为初值，循环计算到delt<0.001;
				rcoor0.Y=rcoor0.Y+Y0;
				rcoor0.Z=rcoor0.Z+Z0;
				reps[0]=rep[0]+rcoor0.P1;
				reps[1]=rep[1]+rcoor0.P2;
				reps[2]=rep[2]+rcoor0.P3;
				delt=rcoor0.X-X0;
				out_biaozhi=1;

			}
		}
		else if(NN>0&&PP>0&&QQ==0&&totle_sat>5)	//GPS/BDS双系统时，为了防止和星历相同时刻时，有单个系统的星为0时，无法解算，程序无法进行，大于5时，RMS才有值20150701,有单个系统的星为0时，可以解算;
		{
			recei_coor(&rcoor0,gps_coor,gps_wj_end,GPS_SR_end,bds_coor,bds_wj_end,BDS_SR_end,totle_sat,NN,PP,&GDOP,&PDOP,T_BBPC.second);//计算接收机坐标,返回位置的改正数rcoor.X、rcoor.Y、rcoor.Z;

			if(rcoor0.X==0&&rcoor0.Y==0&&rcoor0.Z==0)//不能循环太多，比如循环39次，这里的rcoor.X==0&&rcoor.Y==0&&rcoor.Z==0，但是是正确的
			{
				rcoor0.P1=0;
				rcoor0.P2=0;
				break;
			}
			else
			{

				rcoor0.X=rcoor0.X+X0;	//新的接收机坐标=改正数+初值，下面判断，如果delt>0.001的话，返回do，将rcoor.X重新作为初值，循环计算到delt<0.001;
				rcoor0.Y=rcoor0.Y+Y0;
				rcoor0.Z=rcoor0.Z+Z0;
				delt=rcoor0.X-X0;
				out_biaozhi=1;

			}
		}
		else if (NN>4&&PP==0&&QQ==0)//双系统，但只有GPS一种系统可用且大于4时，RMS才有值;
		{
			recei_coor_single(&rcoor0,gps_coor,gps_wj_end,&NN,GPS_SR_end,&GDOP,&PDOP);//计算接收机坐标,返回位置的改正数rcoor.X、rcoor.Y、rcoor.Z;
			if(rcoor0.X==0&&rcoor0.Y==0&&rcoor0.Z==0)//不能循环太多，比如循环39次，这里的rcoor.X==0&&rcoor.Y==0&&rcoor.Z==0，但是是正确的
			{
				break;
			}
			else
			{
				rcoor0.X=rcoor0.X+X0;	//新的接收机坐标=改正数+初值，下面判断，如果delt>0.001的话，返回do，将rcoor.X重新作为初值，循环计算到delt<0.001;
				rcoor0.Y=rcoor0.Y+Y0;
				rcoor0.Z=rcoor0.Z+Z0;
				delt=rcoor0.X-X0;
				rcoor0.P1=rcoor0.P;//单GPS系统钟差给P1;
				out_biaozhi=1;

			}
		}
		else if (NN==0&&PP>4&&QQ==0)//双系统，但只有BDS一种系统可用且大于4时，RMS才有值;
		{
			recei_coor_single(&rcoor0,bds_coor,bds_wj_end,&PP,BDS_SR_end,&GDOP,&PDOP);//计算接收机坐标,返回位置的改正数rcoor.X、rcoor.Y、rcoor.Z;
			if(rcoor0.X==0&&rcoor0.Y==0&&rcoor0.Z==0)//不能循环太多，比如循环39次，这里的rcoor.X==0&&rcoor.Y==0&&rcoor.Z==0，但是是正确的
			{
				break;
			}
			else
			{
				rcoor0.X=rcoor0.X+X0;	//新的接收机坐标=改正数+初值，下面判断，如果delt>0.001的话，返回do，将rcoor.X重新作为初值，循环计算到delt<0.001;
				rcoor0.Y=rcoor0.Y+Y0;
				rcoor0.Z=rcoor0.Z+Z0;
				delt=rcoor0.X-X0;
				rcoor0.P2=rcoor0.P;//单BDS系统钟差给P2;
				out_biaozhi=1;

			}
		}

		else 
			break;

		xhyz++;
	} while (fabs(delt)>0.00001||rcoor0.X==0);
	if (out_biaozhi==1)//剔除钟差;
	{
		for (int j=0;j<BBPC.G_num;j++)
		{
			if(fabs(BBPC.GPC[j])>250)
			{
				//TraceWarn(_T("BBPC %4d %8.1f G%02d %10.3f %10.3f"),BBPC.tg.week,BBPC.tg.second,BBPC.G_PRN[j],BBPC.GPC[j],rcoor0.P1);
				BBPC.GPC[j]	=BBPC.GPC[j]+rcoor0.P1;//接收机钟差影响距离;
			}
			else
			{
				BBPC.GPC[j]	=BBPC.GPC[j];
			}
		}
		for (int i=0;i<BBPC.C_num;i++)
		{
			if(fabs(BBPC.CPC[i])>250)
			{
				//TraceWarn("BBPC %4d %8.1f C%02d %10.3f %10.3f",BBPC.tg.week,BBPC.tg.second,BBPC.C_PRN[i],BBPC.CPC[i],rcoor0.P2);
				BBPC.CPC[i]	=BBPC.CPC[i]+rcoor0.P2;//接收机钟差影响距离;
			}
			else
				BBPC.CPC[i]	=BBPC.CPC[i];
		}
		for (int i=0;i<BBPC.R_num;i++)
		{
			if(fabs(BBPC.RPC[i])>250)
			{
				//TraceWarn("BBPC %4d %8.1f R%02d %10.3f %10.3f",BBPC.tg.week,BBPC.tg.second,BBPC.R_PRN[i],BBPC.RPC[i],rcoor0.P3);
				BBPC.RPC[i]	=BBPC.RPC[i]+rcoor0.P3;//接收机钟差影响距离;
			}
			else
				BBPC.RPC[i]	=BBPC.RPC[i];
		}
	}
	return 0;
}

double CNDGNSS::Produce_ReferenceStation_Corrcetion(DATG dg0,GEPH geph[],IOFH ih0,BS_PR_CR_JH &BBPC)
{

	memset(&BBPC,0x00,sizeof(BBPC));
	//int Bn[30]={0}, Bp[30]={0};
	DATG dg2[1];
	IOFH ih2[1];
	memset(dg2,0x00,sizeof(dg2));
	memset(ih2,0x00,sizeof(ih2));
	dg2[0] = dg0;
	ih2[0] = ih0;

	//int		NN = 0, PP = 0, QQ = 0;						//可利用GPS,BDS,GLONASS卫星数,这里再一次定义是为了将其输出;
	//double	GDOP_raim = 0, PDOP_raim = 0, GDOP1 = 0, PDOP1 = 0, GDOP2 = 0, PDOP2 = 0;

	/************▼基准站改正信息生成▼↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/

	int		Bgps_num, Bbds_num, Bglo_num;		//基准站当前历元GPS、BDS可见卫星数
	memset(&Bgps_num,0,sizeof(Bgps_num));
	memset(&Bbds_num,0,sizeof(Bbds_num));
	memset(&Bglo_num,0,sizeof(Bglo_num));

	//▼▼▼基准站▼▼▼;						
	GPST T_BBPC={0};
	T_BBPC=dg2[0].tg;

	sp		gps_coor,bds_coor,glo_coor;			//卫星坐标_结构体
	memset(&gps_coor,0x00,sizeof(gps_coor));
	memset(&bds_coor,0x00,sizeof(bds_coor));
	memset(&glo_coor,0x00,sizeof(glo_coor));
	double	GDOP=0.0,PDOP=0.0,RMS=0.0,X0=0.0,Y0=0.0,Z0=0.0,delt=0.0;
	int final_N=0,final_P=0,jinxingcuchatichu=0,xhyz=0,out_biaozhi=0;	
	rp rcoor0={0};
	if (T_BBPC.second!=dg2[0].tg.second) return 0;
	BBPC.tg=T_BBPC;//记录基准站GPST
	BBPC.BX = ih2[0].xyz[0];
	BBPC.BY = ih2[0].xyz[1];
	BBPC.BZ = ih2[0].xyz[2];
	rcoor0.X=BBPC.BX;
	rcoor0.Y=BBPC.BY;
	rcoor0.Z=BBPC.BZ;
	do 
	{
		if(xhyz>10) break;
		delt=0.0;													//计算位置坐标，循环置0;
		BBPC.G_num=0;
		BBPC.C_num=0;
		int		g_PRN[32]={0},b_PRN[32]={0};
		double gps_wj_end[32]={0},GPS_SR_end[32]={0};
		double bds_wj_end[32]={0},BDS_SR_end[32]={0};
		double glo_wj[32]={0},GLO_SR[32]={0};
		double	G_XK=0,G_YK=0,G_ZK=0,	B_XK=0,B_YK=0,B_ZK=0,	R_XK=0,R_YK=0,R_ZK=0;
		int		NN=0,PP=0,QQ=0;										//可利用GPS，BDS，GLONASS卫星数，这里再一次定义是为了将其输出;
		int		totle_sat=0;
		X0=rcoor0.X;
		Y0=rcoor0.Y;
		Z0=rcoor0.Z;
		for (int jj = 0; jj < dg2[0].nsat; jj++)
		{
			if (dg2[0].prn[jj] >= 1 &&dg2[0].prn[jj] < 33)
			{
				double g_swj = 0, g_R = 0;
				G_XK = 0, G_YK = 0, G_ZK = 0;
				GNSS_POS_MODULE(geph, dg2, 0, X0, Y0, Z0, &g_swj, &g_R, &G_XK, &G_YK, &G_ZK, jj, 1);//*****dg后面的参数为站号,Njz,(0,1,2,3,4……)为了配合dg【】中的号,最后一位整数1为GPS系统，2为BDS系统!!!!!!!!!!!!!;
				if (g_swj != 0 && g_R != 0)
				{
					/*Bgps_wj[Njz][Bn[Njz]] = g_swj;
					BGPS_SR[Njz][Bn[Njz]] = g_R;*/
					if (xhyz==0)
					{
						BBPC.GPC[BBPC.G_num] = g_R - g_swj;
						BBPC.G_PRN[BBPC.G_num] = dg2[0].prn[jj];
					}
					/*Bgps_coor[Njz].X[Bn[Njz]] = G_XK;
					Bgps_coor[Njz].Y[Bn[Njz]] = G_YK;
					Bgps_coor[Njz].Z[Bn[Njz]] = G_ZK;*/
					//SUM_GPC[Njz]+=BBPC[Njz].GPC[Bn[Njz]];
					//Bn[Njz]++;								        //Bn[Njz]为可利用GPS卫星数目	
					gps_coor.X[BBPC.G_num]		=G_XK;                   //为求接收机钟差，保留卫星坐标，卫星伪距，卫地几何距离20150819;
					gps_coor.Y[BBPC.G_num]		=G_YK;
					gps_coor.Z[BBPC.G_num]		=G_ZK;
					gps_wj_end[BBPC.G_num]     =g_swj;
					GPS_SR_end[BBPC.G_num]		=g_R;
					g_PRN[BBPC.G_num]		=dg2[0].prn[jj];
					BBPC.G_num++;
				}
			}
			//Bgps_num[Njzz]++;							//基准站Njjz当前历元GPS可见卫星数，出错！！！
			if (dg2[0].prn[jj] >= 33 && dg2[0].prn[jj] < 57)
				continue;
			//Bglo_num[Njzz]++;							//基准站Njzz当前历元GLO可见卫星数，出错！！！
			if (dg2[0].prn[jj] >= 161 && dg2[0].prn[jj] < 181)
			{
				continue;
				double b_swj = 0, b_R = 0;
				B_XK = 0, B_YK = 0, B_ZK = 0;
				GNSS_POS_MODULE(geph, dg2, 0, X0, Y0, Z0, &b_swj, &b_R, &B_XK, &B_YK, &B_ZK, jj, 2);//dg后面的参数为站号,0,1,2,3,为了配合dg【】中的号，最后一位整数1为GPS系统，2为BDS系统;
				if (b_swj != 0 && b_R != 0)
				{
					/*Bbds_wj[Njz][Bp[Njz]] = b_swj;
					BBDS_SR[Njz][Bp[Njz]] = b_R;*/
					if (xhyz==0)
					{
						BBPC.CPC[BBPC.C_num] = b_R - b_swj;
						BBPC.C_PRN[BBPC.C_num] = dg2[0].prn[jj];
					}
					/*Bbds_coor[Njz].X[Bp[Njz]] = B_XK;
					Bbds_coor[Njz].Y[Bp[Njz]] = B_YK;
					Bbds_coor[Njz].Z[Bp[Njz]] = B_ZK;*/
					//SUM_CPC[Njz]+=BBPC[Njz].CPC[Bp[Njz]];
					bds_coor.X[BBPC.C_num]		=B_XK;                   //为求接收机钟差，保留卫星坐标，卫星伪距，卫地几何距离20150819;
					bds_coor.Y[BBPC.C_num]		=B_YK;
					bds_coor.Z[BBPC.C_num]		=B_ZK;
					bds_wj_end[BBPC.C_num]     =b_swj;
					BDS_SR_end[BBPC.C_num]		=b_R;
					b_PRN[BBPC.C_num]		=dg2[0].prn[jj];
					BBPC.C_num++;								//Bp[Njz]为可利用GPS卫星数目
				}
			}
			//Bbds_num[Njzz]++;							//基准站Njzz当前历元BDS可见卫星数，出错！！！
		}

		NN=BBPC.G_num;
		PP=BBPC.C_num;
		totle_sat=NN+PP;

		if(NN>0&&PP>0&&totle_sat>5)	//2系统时，为了防止和星历相同时刻时，有单个系统的星为0时，无法解算，程序无法进行，大于5时，RMS才有值20150701,有单个系统的星为0时，可以解算;
		{
			recei_coor(&rcoor0,gps_coor,gps_wj_end,GPS_SR_end,bds_coor,bds_wj_end,BDS_SR_end,totle_sat,NN,PP,&GDOP,&PDOP,T_BBPC.second);//计算接收机坐标,返回位置的改正数rcoor.X、rcoor.Y、rcoor.Z;

			if(rcoor0.X==0&&rcoor0.Y==0&&rcoor0.Z==0)//不能循环太多，比如循环39次，这里的rcoor.X==0&&rcoor.Y==0&&rcoor.Z==0，但是是正确的
			{
				rcoor0.P1=0;
				rcoor0.P2=0;
				break;
			}
			else
			{

				rcoor0.X=rcoor0.X+X0;	//新的接收机坐标=改正数+初值，下面判断，如果delt>0.001的话，返回do，将rcoor.X重新作为初值，循环计算到delt<0.001;
				rcoor0.Y=rcoor0.Y+Y0;
				rcoor0.Z=rcoor0.Z+Z0;
				delt=rcoor0.X-X0;
				out_biaozhi=1;

			}
		}
		else if (NN>4&&PP==0)//双系统，但只有GPS一种系统可用且大于4时，RMS才有值;
		{
			recei_coor_single(&rcoor0,gps_coor,gps_wj_end,&NN,GPS_SR_end,&GDOP,&PDOP);//计算接收机坐标,返回位置的改正数rcoor.X、rcoor.Y、rcoor.Z;
			if(rcoor0.X==0&&rcoor0.Y==0&&rcoor0.Z==0)//不能循环太多，比如循环39次，这里的rcoor.X==0&&rcoor.Y==0&&rcoor.Z==0，但是是正确的
			{
				break;
			}
			else
			{
				rcoor0.X=rcoor0.X+X0;	//新的接收机坐标=改正数+初值，下面判断，如果delt>0.001的话，返回do，将rcoor.X重新作为初值，循环计算到delt<0.001;
				rcoor0.Y=rcoor0.Y+Y0;
				rcoor0.Z=rcoor0.Z+Z0;
				delt=rcoor0.X-X0;
				rcoor0.P1=rcoor0.P;//单GPS系统钟差给P1;
				out_biaozhi=1;

			}
		}
		else if (NN==0&&PP>4)//双系统，但只有BDS一种系统可用且大于4时，RMS才有值;
		{
			recei_coor_single(&rcoor0,bds_coor,bds_wj_end,&PP,BDS_SR_end,&GDOP,&PDOP);//计算接收机坐标,返回位置的改正数rcoor.X、rcoor.Y、rcoor.Z;
			if(rcoor0.X==0&&rcoor0.Y==0&&rcoor0.Z==0)//不能循环太多，比如循环39次，这里的rcoor.X==0&&rcoor.Y==0&&rcoor.Z==0，但是是正确的
			{
				break;
			}
			else
			{
				rcoor0.X=rcoor0.X+X0;	//新的接收机坐标=改正数+初值，下面判断，如果delt>0.001的话，返回do，将rcoor.X重新作为初值，循环计算到delt<0.001;
				rcoor0.Y=rcoor0.Y+Y0;
				rcoor0.Z=rcoor0.Z+Z0;
				delt=rcoor0.X-X0;
				rcoor0.P2=rcoor0.P;//单BDS系统钟差给P2;
				out_biaozhi=1;

			}
		}

		else 
			break;

		xhyz++;
	} while (fabs(delt)>0.0001||rcoor0.X==0);
	if (out_biaozhi==1)//剔除钟差;
	{
		for (int j=0;j<BBPC.G_num;j++)
		{
			if(fabs(BBPC.GPC[j])>250)
			{
				//TraceWarn(_T("BBPC %4d %8.1f G%02d %10.3f %10.3f"),BBPC.tg.week,BBPC.tg.second,BBPC.G_PRN[j],BBPC.GPC[j],rcoor0.P1);
				BBPC.GPC[j]	=BBPC.GPC[j]+rcoor0.P1;//接收机钟差影响距离;
			}
			else
			{
				BBPC.GPC[j]	=BBPC.GPC[j];
			}
		}
		for (int i=0;i<BBPC.C_num;i++)
		{
			if(fabs(BBPC.CPC[i])>250)
			{
				//TraceWarn("BBPC %4d %8.1f C%02d %10.3f %10.3f",BBPC.tg.week,BBPC.tg.second,BBPC.C_PRN[i],BBPC.CPC[i],rcoor0.P2);
				BBPC.CPC[i]	=BBPC.CPC[i]+rcoor0.P2;//接收机钟差影响距离;
			}
			else
				BBPC.CPC[i]	=BBPC.CPC[i];
		}
	}
	return 0;
}

//double CNDGNSS::Produce_Receiver_COOR(DATG dg0,GEPH geph[],IOFH ih0,rp &rcoor0)
//{
//	BS_PR_CR_JH BBPC;
//	memset(&BBPC,0x00,sizeof(BBPC));
//	//int Bn[30]={0}, Bp[30]={0};
//	DATG dg2[1];
//	IOFH ih2[1];
//	memset(dg2,0x00,sizeof(dg2));
//	memset(ih2,0x00,sizeof(ih2));
//	dg2[0] = dg0;
//	ih2[0] = ih0;
//	int G_num=0,C_num=0;
//	//int		NN = 0, PP = 0, QQ = 0;						//可利用GPS,BDS,GLONASS卫星数,这里再一次定义是为了将其输出;
//	//double	GDOP_raim = 0, PDOP_raim = 0, GDOP1 = 0, PDOP1 = 0, GDOP2 = 0, PDOP2 = 0;
//
//	/************▼基准站改正信息生成▼↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
//
//	int		Bgps_num, Bbds_num, Bglo_num;		//基准站当前历元GPS、BDS可见卫星数
//	memset(&Bgps_num,0,sizeof(Bgps_num));
//	memset(&Bbds_num,0,sizeof(Bbds_num));
//	memset(&Bglo_num,0,sizeof(Bglo_num));
//
//	//▼▼▼基准站▼▼▼;						
//	GPST T_BBPC={0};
//	T_BBPC=dg2[0].tg;
//
//	sp		gps_coor,bds_coor,glo_coor;			//卫星坐标_结构体
//	memset(&gps_coor,0x00,sizeof(gps_coor));
//	memset(&bds_coor,0x00,sizeof(bds_coor));
//	memset(&glo_coor,0x00,sizeof(glo_coor));
//	double	GDOP=0.0,PDOP=0.0,RMS=0.0,X0=0.0,Y0=0.0,Z0=0.0,delt=0.0;
//	int final_N=0,final_P=0,jinxingcuchatichu=0,xhyz=0,out_biaozhi=0;	
//	memset(&rcoor0,0x00,sizeof(rcoor0));
//	if (T_BBPC.second!=dg2[0].tg.second) return 0;
//	BBPC.tg=T_BBPC;//记录基准站GPST
//	BBPC.BX = ih2[0].xyz[0];
//	BBPC.BY = ih2[0].xyz[1];
//	BBPC.BZ = ih2[0].xyz[2];
//	//rcoor0.X=BBPC.BX;
//	//rcoor0.Y=BBPC.BY;
//	//rcoor0.Z=BBPC.BZ;
//	rcoor0.X=0.0;
//	rcoor0.Y=0.0;
//	rcoor0.Z=0.0;
//	do 
//	{
//		if(xhyz>10) break;
//		delt=0.0;													//计算位置坐标，循环置0;
//		BBPC.G_num=0;
//		BBPC.C_num=0;
//		int		g_PRN[32]={0},b_PRN[32]={0};
//		double gps_wj_end[32]={0},GPS_SR_end[32]={0};
//		double bds_wj_end[32]={0},BDS_SR_end[32]={0};
//		double glo_wj[32]={0},GLO_SR[32]={0};
//		double	G_XK=0,G_YK=0,G_ZK=0,	B_XK=0,B_YK=0,B_ZK=0,	R_XK=0,R_YK=0,R_ZK=0;
//		int		NN=0,PP=0,QQ=0;										//可利用GPS，BDS，GLONASS卫星数，这里再一次定义是为了将其输出;
//		int		totle_sat=0;
//		X0=rcoor0.X;
//		Y0=rcoor0.Y;
//		Z0=rcoor0.Z;
//		//X0=0.0;
//		//Y0=0.0;
//		//Z0=0.0;
//		for (int jj = 0; jj < dg2[0].nsat; jj++)
//		{
//			if (dg2[0].prn[jj] >= 1 &&dg2[0].prn[jj] < 33)
//			{
//				double g_swj = 0, g_R = 0;
//				G_XK = 0, G_YK = 0, G_ZK = 0;
//				GNSS_POS_MODULE(geph, dg2, 0, X0, Y0, Z0, &g_swj, &g_R, &G_XK, &G_YK, &G_ZK, jj, 1);//*****dg后面的参数为站号,Njz,(0,1,2,3,4……)为了配合dg【】中的号,最后一位整数1为GPS系统，2为BDS系统!!!!!!!!!!!!!;
//				if (g_swj != 0 && g_R != 0)
//				{
//					/*Bgps_wj[Njz][Bn[Njz]] = g_swj;
//					BGPS_SR[Njz][Bn[Njz]] = g_R;*/
//					if (xhyz==0)
//					{
//						BBPC.GPC[BBPC.G_num] = g_R - g_swj;
//						BBPC.G_PRN[BBPC.G_num] = dg2[0].prn[jj];
//					}
//					/*Bgps_coor[Njz].X[Bn[Njz]] = G_XK;
//					Bgps_coor[Njz].Y[Bn[Njz]] = G_YK;
//					Bgps_coor[Njz].Z[Bn[Njz]] = G_ZK;*/
//					//SUM_GPC[Njz]+=BBPC[Njz].GPC[Bn[Njz]];
//					//Bn[Njz]++;								        //Bn[Njz]为可利用GPS卫星数目	
//					gps_coor.X[BBPC.G_num]		=G_XK;                   //为求接收机钟差，保留卫星坐标，卫星伪距，卫地几何距离20150819;
//					gps_coor.Y[BBPC.G_num]		=G_YK;
//					gps_coor.Z[BBPC.G_num]		=G_ZK;
//					gps_wj_end[BBPC.G_num]     =g_swj;
//					GPS_SR_end[BBPC.G_num]		=g_R;
//					g_PRN[BBPC.G_num]		=dg2[0].prn[jj];
//					BBPC.G_num++;
//				}
//			}
//			//Bgps_num[Njzz]++;							//基准站Njjz当前历元GPS可见卫星数，出错！！！
//			if (dg2[0].prn[jj] >= 33 && dg2[0].prn[jj] < 57)
//				continue;
//			//Bglo_num[Njzz]++;							//基准站Njzz当前历元GLO可见卫星数，出错！！！
//			if (dg2[0].prn[jj] >= 57 && dg2[0].prn[jj] < 77)
//			{
//				double b_swj = 0, b_R = 0;
//				B_XK = 0, B_YK = 0, B_ZK = 0;
//				GNSS_POS_MODULE(geph, dg2, 0, X0, Y0, Z0, &b_swj, &b_R, &B_XK, &B_YK, &B_ZK, jj, 2);//dg后面的参数为站号,0,1,2,3,为了配合dg【】中的号，最后一位整数1为GPS系统，2为BDS系统;
//				if (b_swj != 0 && b_R != 0)
//				{
//					/*Bbds_wj[Njz][Bp[Njz]] = b_swj;
//					BBDS_SR[Njz][Bp[Njz]] = b_R;*/
//					if (xhyz==0)
//					{
//						BBPC.CPC[BBPC.C_num] = b_R - b_swj;
//						BBPC.C_PRN[BBPC.C_num] = dg2[0].prn[jj];
//					}
//					/*Bbds_coor[Njz].X[Bp[Njz]] = B_XK;
//					Bbds_coor[Njz].Y[Bp[Njz]] = B_YK;
//					Bbds_coor[Njz].Z[Bp[Njz]] = B_ZK;*/
//					//SUM_CPC[Njz]+=BBPC[Njz].CPC[Bp[Njz]];
//					bds_coor.X[BBPC.C_num]		=B_XK;                   //为求接收机钟差，保留卫星坐标，卫星伪距，卫地几何距离20150819;
//					bds_coor.Y[BBPC.C_num]		=B_YK;
//					bds_coor.Z[BBPC.C_num]		=B_ZK;
//					bds_wj_end[BBPC.C_num]     =b_swj;
//					BDS_SR_end[BBPC.C_num]		=b_R;
//					b_PRN[BBPC.C_num]		=dg2[0].prn[jj];
//					BBPC.C_num++;								//Bp[Njz]为可利用GPS卫星数目
//				}
//			}
//			//Bbds_num[Njzz]++;							//基准站Njzz当前历元BDS可见卫星数，出错！！！
//		}
//
//		NN=BBPC.G_num;
//		PP=BBPC.C_num;
//		totle_sat=NN+PP;
//
//		if(NN>0&&PP>0&&totle_sat>5)	//2系统时，为了防止和星历相同时刻时，有单个系统的星为0时，无法解算，程序无法进行，大于5时，RMS才有值20150701,有单个系统的星为0时，可以解算;
//		{
//			recei_coor(&rcoor0,gps_coor,gps_wj_end,GPS_SR_end,bds_coor,bds_wj_end,BDS_SR_end,totle_sat,NN,PP,&GDOP,&PDOP,T_BBPC.second);//计算接收机坐标,返回位置的改正数rcoor.X、rcoor.Y、rcoor.Z;
//
//			if(rcoor0.X==0&&rcoor0.Y==0&&rcoor0.Z==0)//不能循环太多，比如循环39次，这里的rcoor.X==0&&rcoor.Y==0&&rcoor.Z==0，但是是正确的
//			{
//				rcoor0.P1=0;
//				rcoor0.P2=0;
//				break;
//			}
//			else
//			{
//
//				rcoor0.X=rcoor0.X+X0;	//新的接收机坐标=改正数+初值，下面判断，如果delt>0.001的话，返回do，将rcoor.X重新作为初值，循环计算到delt<0.001;
//				rcoor0.Y=rcoor0.Y+Y0;
//				rcoor0.Z=rcoor0.Z+Z0;
//				delt=rcoor0.X-X0;
//				out_biaozhi=1;
//
//			}
//		}
//		else if (NN>4&&PP==0)//双系统，但只有GPS一种系统可用且大于4时，RMS才有值;
//		{
//			spp_recei_coor_single(&rcoor0,gps_coor,gps_wj_end,&NN,GPS_SR_end,&GDOP,&PDOP);//计算接收机坐标,返回位置的改正数rcoor.X、rcoor.Y、rcoor.Z;
//			if(rcoor0.X==0&&rcoor0.Y==0&&rcoor0.Z==0)//不能循环太多，比如循环39次，这里的rcoor.X==0&&rcoor.Y==0&&rcoor.Z==0，但是是正确的
//			{
//				break;
//			}
//			else
//			{
//				rcoor0.X=rcoor0.X+X0;	//新的接收机坐标=改正数+初值，下面判断，如果delt>0.001的话，返回do，将rcoor.X重新作为初值，循环计算到delt<0.001;
//				rcoor0.Y=rcoor0.Y+Y0;
//				rcoor0.Z=rcoor0.Z+Z0;
//				delt=rcoor0.X-X0;
//				rcoor0.P1=rcoor0.P;//单GPS系统钟差给P1;
//				out_biaozhi=1;
//
//			}
//		}
//		else if (NN==0&&PP>4)//双系统，但只有BDS一种系统可用且大于4时，RMS才有值;
//		{
//			spp_recei_coor_single(&rcoor0,bds_coor,bds_wj_end,&PP,BDS_SR_end,&GDOP,&PDOP);//计算接收机坐标,返回位置的改正数rcoor.X、rcoor.Y、rcoor.Z;
//			if(rcoor0.X==0&&rcoor0.Y==0&&rcoor0.Z==0)//不能循环太多，比如循环39次，这里的rcoor.X==0&&rcoor.Y==0&&rcoor.Z==0，但是是正确的
//			{
//				break;
//			}
//			else
//			{
//				rcoor0.X=rcoor0.X+X0;	//新的接收机坐标=改正数+初值，下面判断，如果delt>0.001的话，返回do，将rcoor.X重新作为初值，循环计算到delt<0.001;
//				rcoor0.Y=rcoor0.Y+Y0;
//				rcoor0.Z=rcoor0.Z+Z0;
//				delt=rcoor0.X-X0;
//				rcoor0.P2=rcoor0.P;//单BDS系统钟差给P2;
//				out_biaozhi=1;
//
//			}
//		}
//
//		else {}
//			//break;
//
//		xhyz++;
//	} while (fabs(delt)>0.0001||rcoor0.X==0);
//	if (out_biaozhi==1)//剔除钟差;
//	{
//		for (int j=0;j<BBPC.G_num;j++)
//		{
//			BBPC.GPC[j]	=BBPC.GPC[j]+rcoor0.P1;//接收机钟差影响距离;
//		}
//		for (int i=0;i<BBPC.C_num;i++)
//		{
//			BBPC.CPC[i]	=BBPC.CPC[i]+rcoor0.P2;//接收机钟差影响距离;
//		}
//	}
//	return 0;
//}
double CNDGNSS::Produce_Receiver_COOR(DATG dg0,GEPH geph[],IOFH ih0,rp &rcoor0)
{
	DATG dg2[1];
	IOFH ih2[1];
	memset(dg2,0x00,sizeof(dg2));
	memset(ih2,0x00,sizeof(ih2));
	dg2[0] = dg0;
	ih2[0] = ih0;
	int G_num,C_num,glo_num;
				
	GPST T_BBPC={0};
	T_BBPC=dg2[0].tg;

	sp		gps_coor,bds_coor,glo_coor;			//卫星坐标_结构体
	memset(&gps_coor,0x00,sizeof(gps_coor));
	memset(&bds_coor,0x00,sizeof(bds_coor));
	memset(&glo_coor,0x00,sizeof(glo_coor));
	double	GDOP=0.0,PDOP=0.0,RMS=0.0,X0=0.0,Y0=0.0,Z0=0.0,delt=0.0;
	int final_N=0,final_P=0,jinxingcuchatichu=0,xhyz=0,out_biaozhi=0;	
	memset(&rcoor0,0x00,sizeof(rcoor0));

	rcoor0.X=0.0;
	rcoor0.Y=0.0;
	rcoor0.Z=0.0;
	do 
	{
		if(xhyz>10) break;//最多循环10次，退出
		delt=0.0;													//计算位置坐标，循环置0;
		G_num=0;
		C_num=0;
		glo_num=0;
		int		g_PRN[32]={0},b_PRN[32]={0},glo_PRN[32]={0};
		double gps_wj_end[32]={0},GPS_SR_end[32]={0};
		double bds_wj_end[32]={0},BDS_SR_end[32]={0};
		double glo_wj_end[32]={0},GLO_SR_end[32]={0};
		double	G_XK=0,G_YK=0,G_ZK=0,	B_XK=0,B_YK=0,B_ZK=0,	R_XK=0,R_YK=0,R_ZK=0;
		int		NN=0,PP=0,QQ=0;										//可利用GPS，BDS，GLONASS卫星数，这里再一次定义是为了将其输出;
		int		totle_sat=0;
		X0=rcoor0.X;//初值为0
		Y0=rcoor0.Y;
		Z0=rcoor0.Z;
		//X0=0.0;
		//Y0=0.0;
		//Z0=0.0;
		for (int jj = 0; jj < dg2[0].nsat; jj++)
		{
			//if (dg2[0].prn[jj] >= 1 &&dg2[0].prn[jj] < 33)
			//{
			//	double g_swj = 0, g_R = 0;
			//	G_XK = 0, G_YK = 0, G_ZK = 0;
			//	GNSS_POS_MODULE(geph, dg2, 0, X0, Y0, Z0, &g_swj, &g_R, &G_XK, &G_YK, &G_ZK, jj, 1);//*****dg后面的参数为站号,Njz,(0,1,2,3,4……)为了配合dg【】中的号,最后一位整数1为GPS系统，2为BDS系统!!!!!!!!!!!!!;
			//	if (g_swj != 0 && g_R != 0)
			//	{
			//		gps_coor.X[G_num]		=G_XK;                   //为求接收机钟差，保留卫星坐标，卫星伪距，卫地几何距离20150819;
			//		gps_coor.Y[G_num]		=G_YK;
			//		gps_coor.Z[G_num]		=G_ZK;
			//		gps_wj_end[G_num]     =g_swj;
			//		GPS_SR_end[G_num]		=g_R;
			//		g_PRN[G_num]		=dg2[0].prn[jj];
			//		G_num++;
			//	}
			//}

			if (dg2[0].prn[jj] >= 1 &&dg2[0].prn[jj] < 33)
			{
				double g_swj = 0, g_R = 0;
				G_XK = 0, G_YK = 0, G_ZK = 0;
				int prn_satellite = dg2[0].prn[jj];
				if (geph[prn_satellite].a[24] == 1)//卫星不健康
					continue;

				double svclk=GetSVpos(dg2[0].tg.week,dg2[0].tg.second,geph[prn_satellite].a,X0,Y0,Z0,&G_XK, &G_YK, &G_ZK); 
				if(svclk > 10.0)
					continue;
				g_R=sqrt(pow(G_XK-X0,2)+pow(G_YK-Y0,2)+pow(G_ZK-Z0,2));//卫地距
				double rs[3]={0.0},rr[3]={0.0},r2suv[3]={0},pos[3]={0},azel[2]={0};
				double EL = 0;
				rs[0]=G_XK;
				rs[1]=G_YK;
				rs[2]=G_ZK;
				rr[0]=X0;
				rr[1]=Y0;
				rr[2]=Z0;
				geodist(rs,rr,r2suv);
				ecef2pos(rr,pos);
				EL=satazel(pos,r2suv,azel);
				if(fabs(EL*R2D)>15.0)//判断卫星高度角
				{
					g_swj = dg2[0].data[jj][0] + svclk*299792458.0 ;//伪距
				}
				else							//高度角为10度((PI/18=0.17453292519943))，小于10的卫星舍去  15度 PI/12=0.2617993877991
				{
					g_R = 0;
					g_swj = 0;
					G_XK = 0;
					G_YK = 0;
					G_ZK = 0;
				}
				if (g_swj != 0 && g_R != 0)
				{
					gps_coor.X[G_num]		=G_XK;                   //为求接收机钟差，保留卫星坐标，卫星伪距，卫地几何距离20150819;
					gps_coor.Y[G_num]		=G_YK;
					gps_coor.Z[G_num]		=G_ZK;
					gps_wj_end[G_num]       =g_swj;
					GPS_SR_end[G_num]		=g_R;
					g_PRN[G_num]		=dg2[0].prn[jj];
					G_num++;
				}
			}

			if (dg2[0].prn[jj] >= 33 && dg2[0].prn[jj] < 57)//glonass，张静云版本，周万振加
			{
				double glo_swj = 0, glo_R = 0;
				R_XK = 0, R_YK = 0, R_ZK = 0;
				int prn_satellite = dg2[0].prn[jj];
				if (geph[prn_satellite].a[8] == 1)//卫星不健康
					continue;
				if (geph[prn_satellite].a[5] == 0.0||geph[prn_satellite].a[9] == 0.0||geph[prn_satellite].a[13] == 0.0)
					continue;

				double  tc=0,tc1=0;
				gtime_t glo_t;
				glo_t.time=geph[prn_satellite].a[0];
				glo_t.sec =geph[prn_satellite].a[1];
				gtime_t glo_ot = gpst2time(dg2[0].tg.week, dg2[0].tg.second);
				double svclk=GetSVpos_GLO(glo_t,glo_ot,dg2[0].data[jj][0],geph[prn_satellite].a,X0,Y0,Z0,&R_XK, &R_YK, &R_ZK,tc);

				if(svclk > 10.0)
					continue;

				glo_R=sqrt(pow(R_XK-X0,2)+pow(R_YK-Y0,2)+pow(R_ZK-Z0,2));//卫地距

				double rs[3]={0.0},rr[3]={0.0},r2suv[3]={0},pos[3]={0},azel[2]={0};
				double EL = 0;
				rs[0]=R_XK;
				rs[1]=R_YK;
				rs[2]=R_ZK;
				rr[0]=X0;
				rr[1]=Y0;
				rr[2]=Z0;
				geodist(rs,rr,r2suv);
				ecef2pos(rr,pos);
				EL=satazel(pos,r2suv,azel);
				if(fabs(EL*R2D)>15.0)//判断卫星高度角
				{
					glo_swj = dg2[0].data[jj][0] + svclk*299792458.0 ;//伪距
				}
				else							//高度角为10度((PI/18=0.17453292519943))，小于10的卫星舍去  15度 PI/12=0.2617993877991
				{
					glo_R = 0;
					glo_swj = 0;
					R_XK = 0;
					R_YK = 0;
					R_ZK = 0;
				}
				if (glo_swj != 0 && glo_R != 0)
				{
					glo_coor.X[glo_num]		=R_XK;                   //为求接收机钟差，保留卫星坐标，卫星伪距，卫地几何距离20150819;
					glo_coor.Y[glo_num]		=R_YK;
					glo_coor.Z[glo_num]		=R_ZK;
					glo_wj_end[glo_num]     =glo_swj;
					GLO_SR_end[glo_num]		=glo_R;
					glo_PRN[glo_num]		=dg2[0].prn[jj];
					glo_num++;
				}
			}

			//if (dg2[0].prn[jj] >= 33 && dg2[0].prn[jj] < 57)//glonass，李鹤峰版本，周万振加
			//{
			//	double glo_swj = 0, glo_R = 0;
			//	R_XK = 0, R_YK = 0, R_ZK = 0;
			//	double rs[6];
			//	memset(rs,0x00,sizeof(rs));
			//	GLO_POS_MODULE(geph,dg2,0,X0,Y0,Z0,&glo_swj,&glo_R,&R_XK,&R_YK,&R_ZK,jj);
			//	if (glo_swj != 0 && glo_R != 0)
			//	{
			//		glo_coor.X[glo_num]		=R_XK;                   //为求接收机钟差，保留卫星坐标，卫星伪距，卫地几何距离20150819;
			//		glo_coor.Y[glo_num]		=R_YK;
			//		glo_coor.Z[glo_num]		=R_ZK;
			//		glo_wj_end[glo_num]     =glo_swj;
			//		GLO_SR_end[glo_num]		=glo_R;
			//		glo_PRN[glo_num]		=dg2[0].prn[jj];
			//		glo_num++;
			//	}
			//}
			//if (dg2[0].prn[jj] >= 33 && dg2[0].prn[jj] < 57)//glonass，周万振版本，周万振加
			//{
			//	//continue;
			//	double glo_swj = 0, glo_R = 0;
			//	double rs[6];
			//	memset(rs,0x00,sizeof(rs));
			//	GLONASS_POS_MODULE(geph,dg2,0,X0,Y0,Z0,&glo_swj,&glo_R,rs,jj);//glonass
			//	if (glo_swj != 0 && glo_R != 0)
			//	{
			//		glo_coor.X[glo_num]		=rs[0];                   //为求接收机钟差，保留卫星坐标，卫星伪距，卫地几何距离20150819;
			//		glo_coor.Y[glo_num]		=rs[1];
			//		glo_coor.Z[glo_num]		=rs[2];
			//		glo_wj_end[glo_num]     =glo_swj;
			//		GLO_SR_end[glo_num]		=glo_R;
			//		glo_PRN[glo_num]		=dg2[0].prn[jj];
			//		glo_num++;
			//	}
			//}

			if (dg2[0].prn[jj] >= 161 && dg2[0].prn[jj] < 181)//BDS
			{
				double b_swj = 0, b_R = 0;
				B_XK = 0, B_YK = 0, B_ZK = 0;
				int prn_satellite = dg2[0].prn[jj];
				if (geph[prn_satellite].a[24] == 1)//卫星不健康
					continue;
				double svclk=0.0;
				if(prn_satellite>165)
				{
					svclk=GetSVpos_BDS(dg2[0].tg.week,dg2[0].tg.second-14,geph[prn_satellite].a,X0,Y0,Z0,&B_XK,&B_YK, &B_ZK); 
					if(svclk > 10.0)
						continue;
				}
				else if(prn_satellite<=165)
				{
					svclk=GetSVpos_GEO(dg2[0].tg.week,dg2[0].tg.second-14,geph[prn_satellite].a,X0,Y0,Z0,&B_XK,&B_YK, &B_ZK);
					if(svclk > 10.0)
						continue;
				}

				b_R=sqrt(pow(B_XK-X0,2)+pow(B_YK-Y0,2)+pow(B_ZK-Z0,2));//卫地距

				double rs[3]={0.0},rr[3]={0.0},r2suv[3]={0},pos[3]={0},azel[2]={0};
				double EL = 0;
				rs[0]=B_XK;
				rs[1]=B_YK;
				rs[2]=B_ZK;
				rr[0]=X0;
				rr[1]=Y0;
				rr[2]=Z0;
				geodist(rs,rr,r2suv);
				ecef2pos(rr,pos);
				EL=satazel(pos,r2suv,azel);
				if(fabs(EL*R2D)>15.0)//判断卫星高度角
				{
					b_swj = dg2[0].data[jj][0] + svclk*299792458.0 ;//伪距
				}
				else							//高度角为10度((PI/18=0.17453292519943))，小于10的卫星舍去  15度 PI/12=0.2617993877991
				{
					b_R = 0;
					b_swj = 0;
					B_XK = 0;
					B_YK = 0;
					B_ZK = 0;
				}
				if (b_swj != 0 && b_R != 0)
				{
					bds_coor.X[C_num]		=B_XK;                   //为求接收机钟差，保留卫星坐标，卫星伪距，卫地几何距离20150819;
					bds_coor.Y[C_num]		=B_YK;
					bds_coor.Z[C_num]		=B_ZK;
					bds_wj_end[C_num]       =b_swj;
					BDS_SR_end[C_num]		=b_R;
					b_PRN[C_num]		=dg2[0].prn[jj];
					C_num++;								//Bp[Njz]为可利用GPS卫星数目
				}
			}
			//if (dg2[0].prn[jj] >= 161 && dg2[0].prn[jj] < 181)
			//{
			//	//continue;
			//	double b_swj = 0, b_R = 0;
			//	B_XK = 0, B_YK = 0, B_ZK = 0;
			//	GNSS_POS_MODULE(geph, dg2, 0, X0, Y0, Z0, &b_swj, &b_R, &B_XK, &B_YK, &B_ZK, jj, 2);//dg后面的参数为站号,0,1,2,3,为了配合dg【】中的号，最后一位整数1为GPS系统，2为BDS系统;
			//	if (b_swj != 0 && b_R != 0)
			//	{
			//		bds_coor.X[C_num]		=B_XK;                   //为求接收机钟差，保留卫星坐标，卫星伪距，卫地几何距离20150819;
			//		bds_coor.Y[C_num]		=B_YK;
			//		bds_coor.Z[C_num]		=B_ZK;
			//		bds_wj_end[C_num]       =b_swj;
			//		BDS_SR_end[C_num]		=b_R;
			//		b_PRN[C_num]		=dg2[0].prn[jj];
			//		C_num++;								//Bp[Njz]为可利用GPS卫星数目
			//	}
			//}
			//Bbds_num[Njzz]++;							//基准站Njzz当前历元BDS可见卫星数，出错！！！
		}

		NN=G_num;
		PP=C_num;
		QQ=glo_num;
		totle_sat=NN+PP+QQ;

		if(NN>0&&PP>0&&QQ>0&&totle_sat>6)	//3系统时，为了防止和星历相同时刻时，有单个系统的星为0时，无法解算，程序无法进行，大于6时，RMS才有值20150701,有单个系统的星为0时，可以解算;
		{
			gps_bds_glo_coor(&rcoor0,gps_coor,gps_wj_end,GPS_SR_end,bds_coor,bds_wj_end,BDS_SR_end,glo_coor,glo_wj_end,GLO_SR_end,totle_sat,NN,PP,QQ,&GDOP,&PDOP,T_BBPC.second);//计算接收机坐标,返回位置的改正数rcoor.X、rcoor.Y、rcoor.Z;

			if(rcoor0.X==0&&rcoor0.Y==0&&rcoor0.Z==0)//不能循环太多，比如循环39次，这里的rcoor.X==0&&rcoor.Y==0&&rcoor.Z==0，但是是正确的
			{
				rcoor0.P1=0;
				rcoor0.P2=0;
				rcoor0.P3=0;
				break;
			}
			else
			{

				rcoor0.X=rcoor0.X+X0;	//新的接收机坐标=改正数+初值，下面判断，如果delt>0.001的话，返回do，将rcoor.X重新作为初值，循环计算到delt<0.001;
				rcoor0.Y=rcoor0.Y+Y0;
				rcoor0.Z=rcoor0.Z+Z0;
				delt=rcoor0.X-X0;
				out_biaozhi=1;

			}
		}
		else if(NN>0&&PP>0&&QQ==0&&totle_sat>5)	//GPS/BDS双系统时，为了防止和星历相同时刻时，有单个系统的星为0时，无法解算，程序无法进行，大于5时，RMS才有值20150701,有单个系统的星为0时，可以解算;
		{
			recei_coor(&rcoor0,gps_coor,gps_wj_end,GPS_SR_end,bds_coor,bds_wj_end,BDS_SR_end,totle_sat,NN,PP,&GDOP,&PDOP,T_BBPC.second);//计算接收机坐标,返回位置的改正数rcoor.X、rcoor.Y、rcoor.Z;

			if(rcoor0.X==0&&rcoor0.Y==0&&rcoor0.Z==0)//不能循环太多，比如循环39次，这里的rcoor.X==0&&rcoor.Y==0&&rcoor.Z==0，但是是正确的
			{
				rcoor0.P1=0;
				rcoor0.P2=0;
				break;
			}
			else
			{

				rcoor0.X=rcoor0.X+X0;	//新的接收机坐标=改正数+初值，下面判断，如果delt>0.001的话，返回do，将rcoor.X重新作为初值，循环计算到delt<0.001;
				rcoor0.Y=rcoor0.Y+Y0;
				rcoor0.Z=rcoor0.Z+Z0;
				delt=rcoor0.X-X0;
				out_biaozhi=1;

			}
		}
		else if (NN>4&&PP==0&&QQ==0)//双系统，但只有GPS一种系统可用且大于4时，RMS才有值;
		{
			spp_recei_coor_single(&rcoor0,gps_coor,gps_wj_end,&NN,GPS_SR_end,&GDOP,&PDOP);//计算接收机坐标,返回位置的改正数rcoor.X、rcoor.Y、rcoor.Z;
			if(rcoor0.X==0&&rcoor0.Y==0&&rcoor0.Z==0)//不能循环太多，比如循环39次，这里的rcoor.X==0&&rcoor.Y==0&&rcoor.Z==0，但是是正确的
			{
				break;
			}
			else
			{
				rcoor0.X=rcoor0.X+X0;	//新的接收机坐标=改正数+初值，下面判断，如果delt>0.001的话，返回do，将rcoor.X重新作为初值，循环计算到delt<0.001;
				rcoor0.Y=rcoor0.Y+Y0;
				rcoor0.Z=rcoor0.Z+Z0;
				delt=rcoor0.X-X0;
				rcoor0.P1=rcoor0.P;//单GPS系统钟差给P1;
				out_biaozhi=1;

			}
		}
		else if (NN==0&&PP>4&&QQ==0)//双系统，但只有BDS一种系统可用且大于4时，RMS才有值;
		{
			spp_recei_coor_single(&rcoor0,bds_coor,bds_wj_end,&PP,BDS_SR_end,&GDOP,&PDOP);//计算接收机坐标,返回位置的改正数rcoor.X、rcoor.Y、rcoor.Z;
			if(rcoor0.X==0&&rcoor0.Y==0&&rcoor0.Z==0)//不能循环太多，比如循环39次，这里的rcoor.X==0&&rcoor.Y==0&&rcoor.Z==0，但是是正确的
			{
				break;
			}
			else
			{
				rcoor0.X=rcoor0.X+X0;	//新的接收机坐标=改正数+初值，下面判断，如果delt>0.001的话，返回do，将rcoor.X重新作为初值，循环计算到delt<0.001;
				rcoor0.Y=rcoor0.Y+Y0;
				rcoor0.Z=rcoor0.Z+Z0;
				delt=rcoor0.X-X0;
				rcoor0.P2=rcoor0.P;//单BDS系统钟差给P2;
				out_biaozhi=1;

			}
		}

		else 
			break;

		xhyz++;
	} while (fabs(delt)>0.0001||rcoor0.X==0);
	rcoor0.ngps = G_num;
	rcoor0.nbds = C_num;
	rcoor0.nglo = glo_num;
	return 0;
}

void CNDGNSS::Choose_BaseStation_for_Grid(IOFH ih0[],int NO_JZZ,NWDGRID GRID,double Grid_Center_Coor[],int IWGD,GridAttribute &GridValue)
{
	memset(&GridValue,0x00,sizeof(GridValue));
	GridValue.Grid_ID=IWGD;//格网ID+1
	double GXYZ[3]={0},BXYZ[3]={0},XYZ[StationNum_USED+1][6];
	for(int tt=1;tt<=NO_JZZ;tt++)//将每个基准站的BLH计算出来，方便下一步使用;
	{
		double xxx,yyy,zzz,bbb,lll,hhh;
		xxx=ih0[tt].xyz[0];
		yyy=ih0[tt].xyz[1];
		zzz=ih0[tt].xyz[2];
		XYZ[tt][0]=ih0[tt].xyz[0];
		XYZ[tt][1]=ih0[tt].xyz[1];
		XYZ[tt][2]=ih0[tt].xyz[2];
		XYZTOBLH (xxx,yyy,zzz,bbb,lll,hhh);
		XYZ[tt][3]=bbb*180/PI;
		XYZ[tt][4]=lll*180/PI;
		XYZ[tt][5]=hhh;
	}
	double Dmin=9999999;
	int j=0;//可以利用的基准站个数;
	GXYZ[0]=Grid_Center_Coor[3];
	GXYZ[1]=Grid_Center_Coor[4];
	GXYZ[2]=Grid_Center_Coor[5];
	GridValue.Grid_Center_Coor[0]=Grid_Center_Coor[0];//格网中心点BLH
	GridValue.Grid_Center_Coor[1]=Grid_Center_Coor[1];
	GridValue.Grid_Center_Coor[2]=Grid_Center_Coor[2];
	GridValue.Grid_Center_Coor[3]=Grid_Center_Coor[3];//格网中心点XYZ
	GridValue.Grid_Center_Coor[4]=Grid_Center_Coor[4];
	GridValue.Grid_Center_Coor[5]=Grid_Center_Coor[5];

	for(int t=1;t<=NO_JZZ;t++)//选出监控站20150713;
	{
		if(XYZ[t][3]>Grid_Center_Coor[0]-2.5*GRID.DLAT&&XYZ[t][3]<Grid_Center_Coor[0]+2.5*GRID.DLAT&&
			XYZ[t][4]>Grid_Center_Coor[1]-2.5*GRID.DLONG&&XYZ[t][4]<Grid_Center_Coor[1]+2.5*GRID.DLONG)
			//首先基准站在以网格点为中心的经纬度为5*网格边界长度的矩形内，这样在基准站较多时可以减少计算量;
		{
			double d=9999999;
			BXYZ[0]=XYZ[t][0];
			BXYZ[1]=XYZ[t][1];
			BXYZ[2]=XYZ[t][2];
			Dist_GB(GXYZ,BXYZ,d);
			if (Dmin>d&&d<50000)//离网格点最近，而且距离范围在50km内20150729;
			{
				Dmin=d;
				GridValue.Monitor_BS_ID=t;//监测站ID
			}
		}
	}
	for(int t=1;t<=NO_JZZ;t++)//选出可用基准站20150713;
	{
		//if (t==NO_GMON[i]) continue;//剔除监控站20150713;基准站太少,不剔除监测站20150805,现在剔除基准站20150901！！！！;
		if(XYZ[t][3]>Grid_Center_Coor[0]-2.5*GRID.DLAT&&XYZ[t][3]<Grid_Center_Coor[0]+2.5*GRID.DLAT&&
			XYZ[t][4]>Grid_Center_Coor[1]-2.5*GRID.DLONG&&XYZ[t][4]<Grid_Center_Coor[1]+2.5*GRID.DLONG)
			//首先基准站在以网格点为中心的经纬度为5*网格边界长度的矩形内，这样在基准站较多时可以减少计算量;
		{
			double d=9999999;
			BXYZ[0]=XYZ[t][0];
			BXYZ[1]=XYZ[t][1];
			BXYZ[2]=XYZ[t][2];
			Dist_GB(GXYZ,BXYZ, d);
			//if(d<100000&&d!=0)//其次,基准站距离网格中心点要在100km内;
			if(d<150000&&d!=0)//其次,基准站距离网格中心点要在100km内;
			//if(d<300000&&d!=0)//其次,基准站距离网格中心点要在300km内;
			{
				GridValue.BS_ID[j]=t;//基准站ID
				GridValue.DistanceOfGB[j]=d;//基准站离中心点距离
				GridValue.Reciprocal_DistanceOfGB[j]=1/d;//基准站离中心点距离的倒数
				j++;
			}
		}
	}
	if (j>0)
	{
		GridValue.BS_Num=j;//基准站数
	}
}

void CNDGNSS::ProduceGridCenterCoor(NWDGRID GRID,double G_C_COORD[][6])
{
	double LONGITUDE0=GRID.LONG0,DLONGITUDE=GRID.DLONG,LATITUDE0=GRID.LAT0,DLATITUDE=GRID.DLAT;
	int NLONGITUDE=GRID.NLONG,NLATITUDE=GRID.NLAT;//输出网格点和历元;
	memset(G_C_COORD,0x00,sizeof(G_C_COORD));

	double lat_Top = LATITUDE0+DLATITUDE*NLATITUDE;
	for(int i=0;i<NLATITUDE;i++)
	{
		for(int j=0;j<NLONGITUDE;j++)
		{
			G_C_COORD[i*NLONGITUDE+j][0]=lat_Top - (i+0.5)*DLATITUDE;//网格中心点纬度B;//编号从左上角开始
			G_C_COORD[i*NLONGITUDE+j][1]=LONGITUDE0+(j+0.5)*DLONGITUDE;//网格中心点经度L;
			G_C_COORD[i*NLONGITUDE+j][2]=0;//网格中心点高程;
			double B,L,H,x,y,z;
			B=G_C_COORD[i*NLONGITUDE+j][0]/180*PI;
			L=G_C_COORD[i*NLONGITUDE+j][1]/180*PI;
			H=0.0;
			BLHTOXYZ ( B, L, H, x, y, z);
			G_C_COORD[i*NLONGITUDE+j][3]=x;
			G_C_COORD[i*NLONGITUDE+j][4]=y;
			G_C_COORD[i*NLONGITUDE+j][5]=z;
		}
	}
}

int CNDGNSS::Search_GridID(double M_coor[],NWDGRID GRID,double G_C_COORD[][6])
{
	int IWGD=99999;
	double LONGITUDE0=GRID.LONG0,DLONGITUDE=GRID.DLONG,LATITUDE0=GRID.LAT0,DLATITUDE=GRID.DLAT;
	int NLONGITUDE=GRID.NLONG,NLATITUDE=GRID.NLAT;//输出网格点和历元;
	double MXYZ[6]={0};//前者用于判断网格,后者用于精度评定;
	XYZTOBLH(M_coor[0],M_coor[1],M_coor[2],MXYZ[0],MXYZ[1],MXYZ[2]);
	for (int ii=0;ii<2;ii++)
	{
		MXYZ[ii+3]=MXYZ[ii]*180/PI;
	}
	for (int iwgd=0;iwgd<NLATITUDE*NLONGITUDE;iwgd++)
	{
		if (MXYZ[3]>=G_C_COORD[iwgd][0]-0.5*DLATITUDE&&MXYZ[3]<G_C_COORD[iwgd][0]+0.5*DLATITUDE&&
			MXYZ[4]>=G_C_COORD[iwgd][1]-0.5*DLONGITUDE&&MXYZ[4]<G_C_COORD[iwgd][1]+0.5*DLONGITUDE)
			//MXYZ中123是弧度,345是BLH.G_C_COORD[iwgd]中123是BLH,判断在哪个网格来用这个网格点的伪距改正数;
		{
			IWGD=iwgd;
			break;
		}
	}
	return IWGD;
}

void CNDGNSS::NWDGNSS_MAIN_MATCH_gps_bds_glo(BS_PR_CR_JH BBPC[],GPST T_BBPC,GridAttribute GridValue,VBS_PR_CR &VBPC)
{
#pragma region NDGNSS
#if 1
	/************▼单个网格虚拟参考站改正信息生成▼↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
	S_PR_CR PC_GRID={0};
	memset(&VBPC,0x00,sizeof(VBPC));
	if (GridValue.BS_Num>2)//当可用基准站数大于等于3时，才可以内插改正数;
	{
		for (int ibs=0;ibs<GridValue.BS_Num;ibs++)//ibs是基准站号;
		{
			if (PC_GRID.G_num==0)//GPS还没有存入星的信息;
			{
				PC_GRID.tg=T_BBPC;
				//PC_GRID.G_num=BPC_JH[NO_Near_GB[igc][ibs]][kbs1].G_num;先赋值还需要减，所以选择后赋值20150701;
				for (int ign=0;ign<BBPC[GridValue.BS_ID[ibs]].G_num;ign++)//将GPS卫星改正数依次付给PC_GRID.G_prn;
				{
					if (BBPC[GridValue.BS_ID[ibs]].GPC[ign]>-250&&BBPC[GridValue.BS_ID[ibs]].GPC[ign]<250)//改正数在±250之间;
					{
						PC_GRID.G_PRN[ign]=BBPC[GridValue.BS_ID[ibs]].G_PRN[ign];
						PC_GRID.GPC[ign][PC_GRID.G_PRN_BSnum[ign]]=BBPC[GridValue.BS_ID[ibs]].GPC[ign];
						PC_GRID.G_PRN_BS[ign][PC_GRID.G_PRN_BSnum[ign]]=ibs;
						PC_GRID.G_PRN_BSnum[ign]++;
						PC_GRID.G_num++;//改正数在±250之间,该星可用,后赋值20150701;
					}
					//else PC_GRID.G_num--;//改正数不在±250之间,该星被剔除,这里减1是因为先赋值了20150701;
				}
			}
			else if (PC_GRID.G_num>0)
			{
				for (int ign=0;ign<BBPC[GridValue.BS_ID[ibs]].G_num;ign++)//寻找基准站上的星在PC_GRID.G_PRN中是否有编号;
				{
					int mm=0;//监测这颗星有没有被存入;
					for (int ign_grid=0;ign_grid<PC_GRID.G_num;ign_grid++)
					{
						if (PC_GRID.G_PRN[ign_grid]==BBPC[GridValue.BS_ID[ibs]].G_PRN[ign]&&
							BBPC[GridValue.BS_ID[ibs]].GPC[ign]>-250&&BBPC[GridValue.BS_ID[ibs]].GPC[ign]<250)//卫星号相同,改正数在±250之间,20150701;
						{
							PC_GRID.GPC[ign_grid][PC_GRID.G_PRN_BSnum[ign_grid]]=BBPC[GridValue.BS_ID[ibs]].GPC[ign];
							PC_GRID.G_PRN_BS[ign_grid][PC_GRID.G_PRN_BSnum[ign_grid]]=ibs;
							PC_GRID.G_PRN_BSnum[ign_grid]++;
							mm=1;
						}
					}
					if (mm==0)//PC_GRID.G_PRN中没有存该星,创建该星;
					{
						if (BBPC[GridValue.BS_ID[ibs]].GPC[ign]>-250&&BBPC[GridValue.BS_ID[ibs]].GPC[ign]<250)//改正数在±250之间;
						{
							PC_GRID.G_PRN[PC_GRID.G_num]=BBPC[GridValue.BS_ID[ibs]].G_PRN[ign];
							PC_GRID.GPC[PC_GRID.G_num][PC_GRID.G_PRN_BSnum[PC_GRID.G_num]]=BBPC[GridValue.BS_ID[ibs]].GPC[ign];
							PC_GRID.G_PRN_BS[PC_GRID.G_num][PC_GRID.G_PRN_BSnum[PC_GRID.G_num]]=ibs;
							PC_GRID.G_PRN_BSnum[PC_GRID.G_num]++;
							PC_GRID.G_num++;
						}
					}
				}
			}
			if (PC_GRID.C_num==0)//BDS还没有存入星的信息;
			{
				if (PC_GRID.tg.second!=T_BBPC.second)
					PC_GRID.tg=T_BBPC;
				for (int icn=0;icn<BBPC[GridValue.BS_ID[ibs]].C_num;icn++)//将BDS卫星改正数依次付给PC_GRID.G_prn;
				{
					if (BBPC[GridValue.BS_ID[ibs]].CPC[icn]>-250&&BBPC[GridValue.BS_ID[ibs]].CPC[icn]<250)
					{
						PC_GRID.C_PRN[icn]=BBPC[GridValue.BS_ID[ibs]].C_PRN[icn];
						PC_GRID.CPC[icn][PC_GRID.C_PRN_BSnum[icn]]=BBPC[GridValue.BS_ID[ibs]].CPC[icn];
						PC_GRID.C_PRN_BS[icn][PC_GRID.C_PRN_BSnum[icn]]=ibs;
						PC_GRID.C_PRN_BSnum[icn]++;
						PC_GRID.C_num++;//改正数在±250之间,该星可用,后赋值20150701;
					}
				}
			}
			else if (PC_GRID.C_num>0)
			{
				for (int icn=0;icn<BBPC[GridValue.BS_ID[ibs]].C_num;icn++)//寻找基准站上的星在PC_GRID.G_PRN中是否有编号;
				{
					int mn=0;//监测这颗星有没有被存入;
					for (int icn_grid=0;icn_grid<PC_GRID.C_num;icn_grid++)
					{
						if (PC_GRID.C_PRN[icn_grid]==BBPC[GridValue.BS_ID[ibs]].C_PRN[icn]&&
							BBPC[GridValue.BS_ID[ibs]].CPC[icn]>-250&&BBPC[GridValue.BS_ID[ibs]].CPC[icn]<250)//卫星号相同,改正数在±250之间,20150701;
						{
							PC_GRID.CPC[icn_grid][PC_GRID.C_PRN_BSnum[icn_grid]]=BBPC[GridValue.BS_ID[ibs]].CPC[icn];
							PC_GRID.C_PRN_BS[icn_grid][PC_GRID.C_PRN_BSnum[icn_grid]]=ibs;
							PC_GRID.C_PRN_BSnum[icn_grid]++;
							mn=1;
						}
					}
					if (mn==0)//PC_GRID.G_PRN中没有存该星,创建该星;
					{
						if (BBPC[GridValue.BS_ID[ibs]].CPC[icn]>-250&&BBPC[GridValue.BS_ID[ibs]].CPC[icn]<250)//改正数在±250之间,20150701;
						{
							PC_GRID.C_PRN[PC_GRID.C_num]=BBPC[GridValue.BS_ID[ibs]].C_PRN[icn];
							PC_GRID.CPC[PC_GRID.C_num][PC_GRID.C_PRN_BSnum[PC_GRID.C_num]]=BBPC[GridValue.BS_ID[ibs]].CPC[icn];
							PC_GRID.C_PRN_BS[PC_GRID.C_num][PC_GRID.C_PRN_BSnum[PC_GRID.C_num]]=ibs;
							PC_GRID.C_PRN_BSnum[PC_GRID.C_num]++;
							PC_GRID.C_num++;
						}
					}
				}
			}
			if (PC_GRID.R_num==0)//GLONASS还没有存入星的信息;
			{
				if (PC_GRID.tg.second!=T_BBPC.second)
					PC_GRID.tg=T_BBPC;
				for (int icn=0;icn<BBPC[GridValue.BS_ID[ibs]].R_num;icn++)//将glo卫星改正数依次付给PC_GRID.G_prn;
				{
					if (BBPC[GridValue.BS_ID[ibs]].RPC[icn]>-250&&BBPC[GridValue.BS_ID[ibs]].RPC[icn]<250)
					{
						PC_GRID.R_PRN[icn]=BBPC[GridValue.BS_ID[ibs]].R_PRN[icn];
						PC_GRID.RPC[icn][PC_GRID.R_PRN_BSnum[icn]]=BBPC[GridValue.BS_ID[ibs]].RPC[icn];
						PC_GRID.R_PRN_BS[icn][PC_GRID.R_PRN_BSnum[icn]]=ibs;
						PC_GRID.R_PRN_BSnum[icn]++;
						PC_GRID.R_num++;//改正数在±250之间,该星可用,后赋值20150701;
					}
				}
			}
			else if (PC_GRID.R_num>0)
			{
				for (int icn=0;icn<BBPC[GridValue.BS_ID[ibs]].R_num;icn++)//寻找基准站上的星在PC_GRID.G_PRN中是否有编号;
				{
					int mr=0;//监测这颗星有没有被存入;
					for (int icn_grid=0;icn_grid<PC_GRID.R_num;icn_grid++)
					{
						if (PC_GRID.R_PRN[icn_grid]==BBPC[GridValue.BS_ID[ibs]].R_PRN[icn]&&
							BBPC[GridValue.BS_ID[ibs]].RPC[icn]>-250&&BBPC[GridValue.BS_ID[ibs]].RPC[icn]<250)//卫星号相同,改正数在±250之间,20150701;
						{
							PC_GRID.RPC[icn_grid][PC_GRID.R_PRN_BSnum[icn_grid]]=BBPC[GridValue.BS_ID[ibs]].RPC[icn];
							PC_GRID.R_PRN_BS[icn_grid][PC_GRID.R_PRN_BSnum[icn_grid]]=ibs;
							PC_GRID.R_PRN_BSnum[icn_grid]++;
							mr=1;
						}
					}
					if (mr==0)//PC_GRID.G_PRN中没有存该星,创建该星;
					{
						if (BBPC[GridValue.BS_ID[ibs]].RPC[icn]>-250&&BBPC[GridValue.BS_ID[ibs]].RPC[icn]<250)//改正数在±250之间,20150701;
						{
							PC_GRID.R_PRN[PC_GRID.R_num]=BBPC[GridValue.BS_ID[ibs]].R_PRN[icn];
							PC_GRID.RPC[PC_GRID.R_num][PC_GRID.R_PRN_BSnum[PC_GRID.R_num]]=BBPC[GridValue.BS_ID[ibs]].RPC[icn];
							PC_GRID.R_PRN_BS[PC_GRID.R_num][PC_GRID.R_PRN_BSnum[PC_GRID.R_num]]=ibs;
							PC_GRID.R_PRN_BSnum[PC_GRID.R_num]++;
							PC_GRID.R_num++;
						}
					}
				}
			}
		}
		double Bsum_GPS_B[40]={0.0},Bsum_BDS_B[40]={0.0},Bm_GPS_B[40][StationNum_USED+1]={0.0},Bm_BDS_B[40][StationNum_USED+1]={0.0},A_GPS_B[40][StationNum_USED+1]={0.0},A_BDS_B[40][StationNum_USED+1]={0.0};
		double Bsum_GLO_B[40]={0.0},Bm_GLO_B[40][StationNum_USED+1]={0.0},A_GLO_B[40][StationNum_USED+1]={0.0};
		int ikygps=0,ikybds=0,ikyglo=0;//网格点上最终的可用卫星数;
		if (PC_GRID.G_num>0)
		{
			for (int igps=0;igps<PC_GRID.G_num;igps++)
			{
				if (PC_GRID.G_PRN_BSnum[igps]>2)
				{
					VBPC.G_PRN[ikygps]=PC_GRID.G_PRN[igps];
					for (int ibss=0;ibss<PC_GRID.G_PRN_BSnum[igps];ibss++)
					{
						Bm_GPS_B[igps][ibss]=GridValue.Reciprocal_DistanceOfGB[PC_GRID.G_PRN_BS[igps][ibss]];
						Bsum_GPS_B[igps]+=Bm_GPS_B[igps][ibss];
					}
					for (int ibsss=0;ibsss<PC_GRID.G_PRN_BSnum[igps];ibsss++)
					{
						A_GPS_B[igps][ibsss]=Bm_GPS_B[igps][ibsss]/Bsum_GPS_B[igps];
						//fprintf(BPCFILE,"BBPC  %6.f %3d G%2d %3d %12.3f %4.3f %10.9f %3d\n",PC_GRID.tg.second,igc,BBPC[igc].G_PRN[ikygps],PC_GRID.G_PRN_BS[igps][ibsss],PC_GRID.GPC[igps][ibsss],A_GPS_B[igps][ibsss],Bm_GPS_B[igps][ibsss],PC_GRID.G_PRN_BSnum[igps]);
						//历元,网格点,G星号,基准站号,伪距改正数,内插系数;
						VBPC.GPC[ikygps]+=A_GPS_B[igps][ibsss]*PC_GRID.GPC[igps][ibsss];
					}
					/*for (int ibssss=0;ibssss<PC_GRID.G_PRN_BSnum[igps];ibssss++)
					{
					BPC_GRID_JH[igc][igzs[igc]].GPC[ikygps]+=A_GPS_B[igps][ibssss]*PC_GRID.GPC[igps][ibssss];
					}*/
					//fprintf(BPCFILE,"VBPC  %6.f %3d G%2d %3d %12.3f\n",PC_GRID.tg.second,igc,PC_GRID.G_PRN[ikygps],PC_GRID.G_PRN_BSnum[igps],PC_GRID.GPC[ikygps]);
					//历元,网格点,G星号,所用基准站数目,伪距改正数;
					ikygps++;
				}
			}
		}
		if (PC_GRID.C_num>0)
		{
			for (int ibds=0;ibds<PC_GRID.C_num;ibds++)
			{
				if (PC_GRID.C_PRN_BSnum[ibds]>2)//控制卫星数大于2;
				{
					/*if (PC_GRID.sow==446847&&igc==3&&ibds==8)
					{
					system("pause");
					}*/
					VBPC.C_PRN[ikybds]=PC_GRID.C_PRN[ibds];
					for (int ibss=0;ibss<PC_GRID.C_PRN_BSnum[ibds];ibss++)
					{
						Bm_BDS_B[ibds][ibss]=GridValue.Reciprocal_DistanceOfGB[PC_GRID.C_PRN_BS[ibds][ibss]];
						Bsum_BDS_B[ibds]+=Bm_BDS_B[ibds][ibss];
					}
					for (int ibsss=0;ibsss<PC_GRID.C_PRN_BSnum[ibds];ibsss++)
					{
						A_BDS_B[ibds][ibsss]=Bm_BDS_B[ibds][ibsss]/Bsum_BDS_B[ibds];
						//fprintf(BPCFILE,"BBPC  %6.f %3d C%2d %3d %12.3f %4.3f %10.9f %3d\n",PC_GRID.tg.second,igc,BBPC[igc].C_PRN[ikybds],PC_GRID.C_PRN_BS[ibds][ibsss],PC_GRID.CPC[ibds][ibsss],A_BDS_B[ibds][ibsss],Bm_BDS_B[ibds][ibsss],PC_GRID.C_PRN_BSnum[ibds]);
						//历元,网格点,C星号,基准站号,伪距改正数,内插系数;
						VBPC.CPC[ikybds]+=A_BDS_B[ibds][ibsss]*PC_GRID.CPC[ibds][ibsss];
					}
					/*for (int ibssss=0;ibssss<PC_GRID.C_PRN_BSnum[ibds];ibssss++)
					{
					BPC_GRID_JH[igc][igzs[igc]].CPC[ikybds]+=A_BDS_B[ibds][ibssss]*PC_GRID.CPC[ibds][ibssss];
					}*/
					//fprintf(BPCFILE,"VBPC  %6.f %3d C%2d %3d %12.3f\n",PC_GRID.tg.second,igc,PC_GRID.C_PRN[ikybds],PC_GRID.C_PRN_BSnum[ibds],PC_GRID.CPC[ikybds]);
					//历元,网格点,C星号,所用基准站数目,伪距改正数;
					ikybds++;
				}
			}
		}
		if (PC_GRID.R_num>0)//glonass
		{
			for (int iglo=0;iglo<PC_GRID.R_num;iglo++)
			{
				if (PC_GRID.R_PRN_BSnum[iglo]>2)//控制卫星数大于2;
				{
					/*if (PC_GRID.sow==446847&&igc==3&&ibds==8)
					{
					system("pause");
					}*/
					VBPC.R_PRN[ikyglo]=PC_GRID.R_PRN[iglo];
					for (int ibss=0;ibss<PC_GRID.R_PRN_BSnum[iglo];ibss++)
					{
						Bm_GLO_B[iglo][ibss]=GridValue.Reciprocal_DistanceOfGB[PC_GRID.R_PRN_BS[iglo][ibss]];
						Bsum_GLO_B[iglo]+=Bm_GLO_B[iglo][ibss];
					}
					for (int ibsss=0;ibsss<PC_GRID.R_PRN_BSnum[iglo];ibsss++)
					{
						A_GLO_B[iglo][ibsss]=Bm_GLO_B[iglo][ibsss]/Bsum_GLO_B[iglo];
						//fprintf(BPCFILE,"BBPC  %6.f %3d C%2d %3d %12.3f %4.3f %10.9f %3d\n",PC_GRID.tg.second,igc,BBPC[igc].C_PRN[ikybds],PC_GRID.C_PRN_BS[ibds][ibsss],PC_GRID.CPC[ibds][ibsss],A_BDS_B[ibds][ibsss],Bm_BDS_B[ibds][ibsss],PC_GRID.C_PRN_BSnum[ibds]);
						//历元,网格点,C星号,基准站号,伪距改正数,内插系数;
						VBPC.RPC[ikyglo]+=A_GLO_B[iglo][ibsss]*PC_GRID.RPC[iglo][ibsss];
					}
					/*for (int ibssss=0;ibssss<PC_GRID.C_PRN_BSnum[ibds];ibssss++)
					{
					BPC_GRID_JH[igc][igzs[igc]].CPC[ikybds]+=A_BDS_B[ibds][ibssss]*PC_GRID.CPC[ibds][ibssss];
					}*/
					//fprintf(BPCFILE,"VBPC  %6.f %3d C%2d %3d %12.3f\n",PC_GRID.tg.second,igc,PC_GRID.C_PRN[ikybds],PC_GRID.C_PRN_BSnum[ibds],PC_GRID.CPC[ikybds]);
					//历元,网格点,C星号,所用基准站数目,伪距改正数;
					ikyglo++;
				}
			}
		}
		double maxgps,maxbds,maxglo;
		do
		{
			maxgps=0.0;
			maxbds=0.0;
			maxglo=0.0;
			double sumgps=0.0,sumbds=0.0,avgps=0.0,avbds=0.0;
			double sumglo=0.0,avglo=0.0;
			int maxgpsid=0,maxbdsid=0,maxgloid=0;
			if(ikygps>0)//GPS伪距粗差剔除20150807;
			{
				for(int ig=0;ig<ikygps;ig++)
				{
					sumgps+=VBPC.GPC[ig];
				}
				avgps=sumgps/ikygps;
				for(int ig=0;ig<ikygps;ig++)
				{
					double agps=0.0;
					agps=fabs(VBPC.GPC[ig]-avgps);
					if(agps>maxgps)
					{
						maxgps=agps;
						maxgpsid=ig;
					}
				}
				if(maxgps>250)//坏星,与其它星伪距改正数相差太大,剔除偏差最大的那颗星;
				{
					for(int igh=maxgpsid;igh<ikygps;igh++)
					{
						VBPC.G_PRN[igh]=VBPC.G_PRN[igh+1];
						VBPC.GPC[igh]=VBPC.GPC[igh+1];
					}
					ikygps--;
				}
			}

			if(ikybds>0)//BDS伪距粗差剔除;//问题排查20160813
			{
				for(int ib=0;ib<ikybds;ib++)
				{
					sumbds+=VBPC.CPC[ib];
				}
				avbds=sumbds/ikybds;
				for(int ib=0;ib<ikybds;ib++)
				{
					double abds=0.0;
					abds=fabs(VBPC.CPC[ib]-avbds);
					if(abds>maxbds)
					{
						maxbds=abds;
						maxbdsid=ib;
					}
				}
				if(maxbds>250)//坏星,与其它星伪距改正数相差太大,剔除偏差最大的那颗星;
				{
					for(int ibh=maxbdsid;ibh<ikybds;ibh++)
					{
						VBPC.C_PRN[ibh]=VBPC.C_PRN[ibh+1];
						VBPC.CPC[ibh]=VBPC.CPC[ibh+1];
					}
					ikybds--;
				}
			}
			if(ikyglo>0)//GLONASS伪距粗差剔除20160813;
			{
				for(int ib=0;ib<ikyglo;ib++)
				{
					sumglo+=VBPC.RPC[ib];
				}
				avglo=sumglo/ikyglo;
				for(int ib=0;ib<ikyglo;ib++)
				{
					double abds=0.0;
					abds=fabs(VBPC.RPC[ib]-avglo);
					if(abds>maxglo)
					{
						maxglo=abds;
						maxgloid=ib;
					}
				}
				if(maxglo>250)//坏星,与其它星伪距改正数相差太大,剔除偏差最大的那颗星;
				{
					for(int ibh=maxgloid;ibh<ikyglo;ibh++)
					{
						VBPC.R_PRN[ibh]=VBPC.R_PRN[ibh+1];
						VBPC.RPC[ibh]=VBPC.RPC[ibh+1];
					}
					ikyglo--;
				}
			}
		}while(maxgps>250||maxbds>250||maxglo>250);
		if (ikygps>0||ikybds>0||ikyglo>0)
		{
			//赋值;
			VBPC.tg=PC_GRID.tg;
			VBPC.G_num=ikygps;
			VBPC.C_num=ikybds;
			VBPC.R_num=ikyglo;
		}

	}

#endif
#pragma endregion
}

void CNDGNSS::NWDGNSS_MAIN_MATCH(BS_PR_CR_JH BBPC[],GPST T_BBPC,GridAttribute GridValue,VBS_PR_CR &VBPC)
{
#pragma region NDGNSS
#if 1
	/************▼单个网格虚拟参考站改正信息生成▼↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
	S_PR_CR PC_GRID={0};
	memset(&VBPC,0x00,sizeof(VBPC));
	if (GridValue.BS_Num>2)//当可用基准站数大于等于3时，才可以内插改正数;
	{
		for (int ibs=0;ibs<GridValue.BS_Num;ibs++)//ibs是基准站号;
		{
			if (PC_GRID.G_num==0)//GPS还没有存入星的信息;
			{
				PC_GRID.tg=T_BBPC;
				//PC_GRID.G_num=BPC_JH[NO_Near_GB[igc][ibs]][kbs1].G_num;先赋值还需要减，所以选择后赋值20150701;
				for (int ign=0;ign<BBPC[GridValue.BS_ID[ibs]].G_num;ign++)//将GPS卫星改正数依次付给PC_GRID.G_prn;
				{
					if (BBPC[GridValue.BS_ID[ibs]].GPC[ign]>-250&&BBPC[GridValue.BS_ID[ibs]].GPC[ign]<250)//改正数在±250之间;
					{
						PC_GRID.G_PRN[ign]=BBPC[GridValue.BS_ID[ibs]].G_PRN[ign];
						PC_GRID.GPC[ign][PC_GRID.G_PRN_BSnum[ign]]=BBPC[GridValue.BS_ID[ibs]].GPC[ign];
						PC_GRID.G_PRN_BS[ign][PC_GRID.G_PRN_BSnum[ign]]=ibs;
						PC_GRID.G_PRN_BSnum[ign]++;
						PC_GRID.G_num++;//改正数在±250之间,该星可用,后赋值20150701;
					}
					//else PC_GRID.G_num--;//改正数不在±250之间,该星被剔除,这里减1是因为先赋值了20150701;
				}
			}
			else if (PC_GRID.G_num>0)
			{
				for (int ign=0;ign<BBPC[GridValue.BS_ID[ibs]].G_num;ign++)//寻找基准站上的星在PC_GRID.G_PRN中是否有编号;
				{
					int mm=0;//监测这颗星有没有被存入;
					for (int ign_grid=0;ign_grid<PC_GRID.G_num;ign_grid++)
					{
						if (PC_GRID.G_PRN[ign_grid]==BBPC[GridValue.BS_ID[ibs]].G_PRN[ign]&&
							BBPC[GridValue.BS_ID[ibs]].GPC[ign]>-250&&BBPC[GridValue.BS_ID[ibs]].GPC[ign]<250)//卫星号相同,改正数在±250之间,20150701;
						{
							PC_GRID.GPC[ign_grid][PC_GRID.G_PRN_BSnum[ign_grid]]=BBPC[GridValue.BS_ID[ibs]].GPC[ign];
							PC_GRID.G_PRN_BS[ign_grid][PC_GRID.G_PRN_BSnum[ign_grid]]=ibs;
							PC_GRID.G_PRN_BSnum[ign_grid]++;
							mm=1;
						}
					}
					if (mm==0)//PC_GRID.G_PRN中没有存该星,创建该星;
					{
						if (BBPC[GridValue.BS_ID[ibs]].GPC[ign]>-250&&BBPC[GridValue.BS_ID[ibs]].GPC[ign]<250)//改正数在±250之间;
						{
							PC_GRID.G_PRN[PC_GRID.G_num]=BBPC[GridValue.BS_ID[ibs]].G_PRN[ign];
							PC_GRID.GPC[PC_GRID.G_num][PC_GRID.G_PRN_BSnum[PC_GRID.G_num]]=BBPC[GridValue.BS_ID[ibs]].GPC[ign];
							PC_GRID.G_PRN_BS[PC_GRID.G_num][PC_GRID.G_PRN_BSnum[PC_GRID.G_num]]=ibs;
							PC_GRID.G_PRN_BSnum[PC_GRID.G_num]++;
							PC_GRID.G_num++;
						}
					}
				}
			}
			if (PC_GRID.C_num==0)//BDS还没有存入星的信息;
			{
				if (PC_GRID.tg.second!=T_BBPC.second)
					PC_GRID.tg=T_BBPC;
				for (int icn=0;icn<BBPC[GridValue.BS_ID[ibs]].C_num;icn++)//将BDS卫星改正数依次付给PC_GRID.G_prn;
				{
					if (BBPC[GridValue.BS_ID[ibs]].CPC[icn]>-250&&BBPC[GridValue.BS_ID[ibs]].CPC[icn]<250)
					{
						PC_GRID.C_PRN[icn]=BBPC[GridValue.BS_ID[ibs]].C_PRN[icn];
						PC_GRID.CPC[icn][PC_GRID.C_PRN_BSnum[icn]]=BBPC[GridValue.BS_ID[ibs]].CPC[icn];
						PC_GRID.C_PRN_BS[icn][PC_GRID.C_PRN_BSnum[icn]]=ibs;
						PC_GRID.C_PRN_BSnum[icn]++;
						PC_GRID.C_num++;//改正数在±250之间,该星可用,后赋值20150701;
					}
				}
			}
			else if (PC_GRID.C_num>0)
			{
				for (int icn=0;icn<BBPC[GridValue.BS_ID[ibs]].C_num;icn++)//寻找基准站上的星在PC_GRID.G_PRN中是否有编号;
				{
					int mn=0;//监测这颗星有没有被存入;
					for (int icn_grid=0;icn_grid<PC_GRID.C_num;icn_grid++)
					{
						if (PC_GRID.C_PRN[icn_grid]==BBPC[GridValue.BS_ID[ibs]].C_PRN[icn]&&
							BBPC[GridValue.BS_ID[ibs]].CPC[icn]>-250&&BBPC[GridValue.BS_ID[ibs]].CPC[icn]<250)//卫星号相同,改正数在±250之间,20150701;
						{
							PC_GRID.CPC[icn_grid][PC_GRID.C_PRN_BSnum[icn_grid]]=BBPC[GridValue.BS_ID[ibs]].CPC[icn];
							PC_GRID.C_PRN_BS[icn_grid][PC_GRID.C_PRN_BSnum[icn_grid]]=ibs;
							PC_GRID.C_PRN_BSnum[icn_grid]++;
							mn=1;
						}
					}
					if (mn==0)//PC_GRID.G_PRN中没有存该星,创建该星;
					{
						if (BBPC[GridValue.BS_ID[ibs]].CPC[icn]>-250&&BBPC[GridValue.BS_ID[ibs]].CPC[icn]<250)//改正数在±250之间,20150701;
						{
							PC_GRID.C_PRN[PC_GRID.C_num]=BBPC[GridValue.BS_ID[ibs]].C_PRN[icn];
							PC_GRID.CPC[PC_GRID.C_num][PC_GRID.C_PRN_BSnum[PC_GRID.C_num]]=BBPC[GridValue.BS_ID[ibs]].CPC[icn];
							PC_GRID.C_PRN_BS[PC_GRID.C_num][PC_GRID.C_PRN_BSnum[PC_GRID.C_num]]=ibs;
							PC_GRID.C_PRN_BSnum[PC_GRID.C_num]++;
							PC_GRID.C_num++;
						}
					}
				}
			}



		}
		double Bsum_GPS_B[32]={0.0},Bsum_BDS_B[32]={0.0},Bm_GPS_B[32][20]={0.0},Bm_BDS_B[32][20]={0.0},A_GPS_B[32][20]={0.0},A_BDS_B[32][20]={0.0};
		int ikygps=0,ikybds=0;//网格点上最终的可用卫星数;
		if (PC_GRID.G_num>0)
		{
			for (int igps=0;igps<PC_GRID.G_num;igps++)
			{
				if (PC_GRID.G_PRN_BSnum[igps]>2)
				{
					VBPC.G_PRN[ikygps]=PC_GRID.G_PRN[igps];
					for (int ibss=0;ibss<PC_GRID.G_PRN_BSnum[igps];ibss++)
					{
						Bm_GPS_B[igps][ibss]=GridValue.Reciprocal_DistanceOfGB[PC_GRID.G_PRN_BS[igps][ibss]];
						Bsum_GPS_B[igps]+=Bm_GPS_B[igps][ibss];
					}
					for (int ibsss=0;ibsss<PC_GRID.G_PRN_BSnum[igps];ibsss++)
					{
						A_GPS_B[igps][ibsss]=Bm_GPS_B[igps][ibsss]/Bsum_GPS_B[igps];
						//fprintf(BPCFILE,"BBPC  %6.f %3d G%2d %3d %12.3f %4.3f %10.9f %3d\n",PC_GRID.tg.second,igc,BBPC[igc].G_PRN[ikygps],PC_GRID.G_PRN_BS[igps][ibsss],PC_GRID.GPC[igps][ibsss],A_GPS_B[igps][ibsss],Bm_GPS_B[igps][ibsss],PC_GRID.G_PRN_BSnum[igps]);
						//历元,网格点,G星号,基准站号,伪距改正数,内插系数;
						VBPC.GPC[ikygps]+=A_GPS_B[igps][ibsss]*PC_GRID.GPC[igps][ibsss];
					}
					/*for (int ibssss=0;ibssss<PC_GRID.G_PRN_BSnum[igps];ibssss++)
					{
					BPC_GRID_JH[igc][igzs[igc]].GPC[ikygps]+=A_GPS_B[igps][ibssss]*PC_GRID.GPC[igps][ibssss];
					}*/
					//fprintf(BPCFILE,"VBPC  %6.f %3d G%2d %3d %12.3f\n",PC_GRID.tg.second,igc,PC_GRID.G_PRN[ikygps],PC_GRID.G_PRN_BSnum[igps],PC_GRID.GPC[ikygps]);
					//历元,网格点,G星号,所用基准站数目,伪距改正数;
					ikygps++;
				}
			}
		}
		if (PC_GRID.C_num>0)
		{
			for (int ibds=0;ibds<PC_GRID.C_num;ibds++)
			{
				if (PC_GRID.C_PRN_BSnum[ibds]>2)//控制卫星数大于2;
				{
					/*if (PC_GRID.sow==446847&&igc==3&&ibds==8)
					{
					system("pause");
					}*/
					VBPC.C_PRN[ikybds]=PC_GRID.C_PRN[ibds];
					for (int ibss=0;ibss<PC_GRID.C_PRN_BSnum[ibds];ibss++)
					{
						Bm_BDS_B[ibds][ibss]=GridValue.Reciprocal_DistanceOfGB[PC_GRID.C_PRN_BS[ibds][ibss]];
						Bsum_BDS_B[ibds]+=Bm_BDS_B[ibds][ibss];
					}
					for (int ibsss=0;ibsss<PC_GRID.C_PRN_BSnum[ibds];ibsss++)
					{
						A_BDS_B[ibds][ibsss]=Bm_BDS_B[ibds][ibsss]/Bsum_BDS_B[ibds];
						//fprintf(BPCFILE,"BBPC  %6.f %3d C%2d %3d %12.3f %4.3f %10.9f %3d\n",PC_GRID.tg.second,igc,BBPC[igc].C_PRN[ikybds],PC_GRID.C_PRN_BS[ibds][ibsss],PC_GRID.CPC[ibds][ibsss],A_BDS_B[ibds][ibsss],Bm_BDS_B[ibds][ibsss],PC_GRID.C_PRN_BSnum[ibds]);
						//历元,网格点,C星号,基准站号,伪距改正数,内插系数;
						VBPC.CPC[ikybds]+=A_BDS_B[ibds][ibsss]*PC_GRID.CPC[ibds][ibsss];
					}
					/*for (int ibssss=0;ibssss<PC_GRID.C_PRN_BSnum[ibds];ibssss++)
					{
					BPC_GRID_JH[igc][igzs[igc]].CPC[ikybds]+=A_BDS_B[ibds][ibssss]*PC_GRID.CPC[ibds][ibssss];
					}*/
					//fprintf(BPCFILE,"VBPC  %6.f %3d C%2d %3d %12.3f\n",PC_GRID.tg.second,igc,PC_GRID.C_PRN[ikybds],PC_GRID.C_PRN_BSnum[ibds],PC_GRID.CPC[ikybds]);
					//历元,网格点,C星号,所用基准站数目,伪距改正数;
					ikybds++;
				}
			}
		}
		double maxgps,maxbds;
		do
		{
			maxgps=0.0;
			maxbds=0.0;
			double sumgps=0.0,sumbds=0.0,avgps=0.0,avbds=0.0;
			int maxgpsid=0,maxbdsid=0;
			if(ikygps>0)//GPS伪距粗差剔除20150807;
			{
				for(int ig=0;ig<ikygps;ig++)
				{
					sumgps+=VBPC.GPC[ig];
				}
				avgps=sumgps/ikygps;
				for(int ig=0;ig<ikygps;ig++)
				{
					double agps=0.0;
					agps=fabs(VBPC.GPC[ig]-avgps);
					if(agps>maxgps)
					{
						maxgps=agps;
						maxgpsid=ig;
					}
				}
				if(maxgps>250)//坏星,与其它星伪距改正数相差太大,剔除偏差最大的那颗星;
				{
					for(int igh=maxgpsid;igh<ikygps;igh++)
					{
						VBPC.G_PRN[igh]=VBPC.G_PRN[igh+1];
						VBPC.GPC[igh]=VBPC.GPC[igh+1];
					}
					ikygps--;
				}
			}

			if(ikybds>0)//BDS伪距粗差剔除20150807;
			{
				for(int ib=0;ib<ikybds;ib++)
				{
					sumbds+=VBPC.CPC[ib];
				}
				avbds=sumbds/ikybds;
				for(int ib=0;ib<ikygps;ib++)
				{
					double abds=0.0;
					abds=fabs(VBPC.CPC[ib]-avbds);
					if(abds>maxbds)
					{
						maxbds=abds;
						maxbdsid=ib;
					}
				}
				if(maxbds>250)//坏星,与其它星伪距改正数相差太大,剔除偏差最大的那颗星;
				{
					for(int ibh=maxbdsid;ibh<ikybds;ibh++)
					{
						VBPC.C_PRN[ibh]=VBPC.C_PRN[ibh+1];
						VBPC.CPC[ibh]=VBPC.CPC[ibh+1];
					}
					ikybds--;
				}
			}
		}while(maxgps>250||maxbds>250);
		if (ikygps>0||ikybds>0)
		{
			//赋值;
			VBPC.tg=PC_GRID.tg;
			VBPC.G_num=ikygps;
			VBPC.C_num=ikybds;
		}

	}

#endif
#pragma endregion
}

void CNDGNSS::NWDGNSS_3SYS_MOVING_POS_MODULE_RAIM(GridAttribute GridValue,double  M_coor[],VBS_PR_CR VBPC[], DATG dg0, GEPH geph[],rp &rcoor2,Sate_NUM &sate_num)
{
	double	delt = 1;								//do...while()限制条件中的接收机X坐标迭代控制条件
	double	GDOP2 = 0, PDOP2 = 0;
	DATG dg[5] = { 0 };
	//int i = 0;
	dg[1] = dg0;
	BS_PR_CR BPC={0};

	//这里因为是车载，所以流动站一直在变，那么如果流动站有坐标，就用流动站坐标到各基准站的距离，如果流动站坐标为0，就用监测站坐标，一般流动站第一次坐标为0，以后都会有值，为上一次的解得的值;
	IOFH ih3[4] = { 0 };

	int IWGD=GridValue.Grid_ID;//所需的格网ID
	int pp=0;
	int nn1=0;
	int rr=0;
	if(IWGD!=99999&&fabs(VBPC[IWGD].tg.second-dg[1].tg.second)<5.0)//匹配历元,流动站历元与改正数历元要相同20150807;
	{
		for(int n1 = 0 ;n1 < VBPC[IWGD].G_num; n1++)
		{
			BPC.G_PRN[n1] = VBPC[IWGD].G_PRN[n1];
			BPC.GPC[n1] = VBPC[IWGD].GPC[n1];
		}

		for(int p1 = 0 ;p1 < VBPC[IWGD].C_num; p1++)
		{
			BPC.C_PRN[p1] = VBPC[IWGD].C_PRN[p1];
			BPC.CPC[p1] = VBPC[IWGD].CPC[p1];
		}
		for(int r1 = 0 ;r1 < VBPC[IWGD].R_num; r1++)
		{
			BPC.R_PRN[r1] = VBPC[IWGD].R_PRN[r1];
			BPC.RPC[r1] = VBPC[IWGD].RPC[r1];
		}
		nn1=VBPC[IWGD].G_num;
		pp=VBPC[IWGD].C_num;
		rr=VBPC[IWGD].R_num;

		/************▼流动站1  dg[1]计算▼↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/

		double	M2X0, M2Y0, M2Z0;							//流动站初始坐标;
		double	M2g_swj, M2g_R, M2b_swj, M2b_R, M2r_swj, M2r_R;
		double	M2G_XK, M2G_YK, M2G_ZK, M2B_XK, M2B_YK, M2B_ZK, M2R_XK, M2R_YK, M2R_ZK;	//初始坐标;
		int		MM2, KK2, RR2, ALL_GB2;
		double	M2gps_wj[32] = { 0 }, M2GPS_SR[32] = { 0 };	//流动站解算的gps伪距&近似距离——存储值;
		double	M2bds_wj[35] = { 0 }, M2BDS_SR[35] = { 0 };	//流动站解算的bds伪距&近似距离——存储值;
		double	M2glo_wj[35] = { 0 }, M2GLO_SR[35] = { 0 };	//流动站解算的glo伪距&近似距离——存储值;
		int		M2GPRN[32] = { 0 };						//流动站gpsPRN号——存储值;
		int		M2BPRN[35] = { 0 };						//流动站bdsPRN号——存储值;
		int		M2RPRN[35] = { 0 };						//流动站bdsPRN号——存储值;
		sp		M2gps_coor = { 0 }, M2bds_coor = { 0 }, M2glo_coor = { 0 };		//流动站解算的gps与bds的卫星坐标——存储值;

		double	M2_gps_wj[32] = { 0 }, M2_GPS_SR[32] = { 0 };//流动站最终解算;
		double	M2_bds_wj[35] = { 0 }, M2_BDS_SR[35] = { 0 };//流动站最终解算;
		double	M2_glo_wj[35] = { 0 }, M2_GLO_SR[35] = { 0 };//流动站最终解算;
		int		M2_GPRN[32] = { 0 };					//流动站最终解算;
		int		M2_BPRN[35] = { 0 };					//流动站最终解算;
		int		M2_RPRN[35] = { 0 };					//流动站最终解算;
		sp		M2_gps_coor = { 0 }, M2_bds_coor = { 0 }, M2_glo_coor = { 0 };	//流动站最终解算;


		double check2_gps[32] = { 0 }, check2_bds[35] = { 0 }, check2_glo[35] = { 0 };//检测伪距改正输出;

		rcoor2.X = M_coor[0];
		rcoor2.Y = M_coor[1];
		rcoor2.Z = M_coor[2];


		int xunhuan=0;
		do		//最多循环10次跳出，代替do。。。。while;
		{ 


			if( xunhuan>14)	{break;}		//最多循环10次跳出，代替do。。。。while;
			xunhuan++;
			int	m2 = 0, k2 = 0, r2 = 0;								//循环回代置零;
			M2X0 = rcoor2.X;								//用于循环回代;
			M2Y0 = rcoor2.Y;
			M2Z0 = rcoor2.Z;

			for (int ii = 0; ii<dg[1].nsat; ii++)				//基于流动站计算卫星位置及伪距&卫地距;
			{
				if(dg[1].prn[ii] >= 1 &&dg[1].prn[ii] < 33)
				{
					M2g_swj = 0, M2g_R = 0;
					M2G_XK = 0, M2G_YK = 0, M2G_ZK = 0;
					int prn_satellite = dg[1].prn[ii];
					if (geph[prn_satellite].a[24] == 1)//卫星不健康
						continue;

					double svclk=GetSVpos(dg[1].tg.week,dg[1].tg.second,geph[prn_satellite].a,M2X0, M2Y0, M2Z0,&M2G_XK, &M2G_YK, &M2G_ZK); 
					if(svclk > 10.0)
						continue;
					M2g_R=sqrt(pow(M2G_XK-M2X0,2)+pow(M2G_YK-M2Y0,2)+pow(M2G_ZK-M2Z0,2));//卫地距
					double rs[3]={0.0},rr[3]={0.0},r2suv[3]={0},pos[3]={0},azel[2]={0};
					double EL = 0;
					rs[0]=M2G_XK;
					rs[1]=M2G_YK;
					rs[2]=M2G_ZK;
					rr[0]=M2X0;
					rr[1]=M2Y0;
					rr[2]=M2Z0;
					geodist(rs,rr,r2suv);
					ecef2pos(rr,pos);
					EL=satazel(pos,r2suv,azel);
					if(fabs(EL*R2D)>15.0)//判断卫星高度角
					{
						M2g_swj = dg[1].data[ii][0] + svclk*299792458.0 ;//伪距
					}
					else							//高度角为10度((PI/18=0.17453292519943))，小于10的卫星舍去  15度 PI/12=0.2617993877991
					{
						M2g_R = 0;
						M2g_swj = 0;
						M2G_XK = 0;
						M2G_YK = 0;
						M2G_ZK = 0;
					}
					if (M2g_swj != 0 && M2g_R != 0)
					{
						M2gps_wj[m2] = M2g_swj;
						M2GPS_SR[m2] = M2g_R;
						M2GPRN[m2] = dg[1].prn[ii];
						M2gps_coor.X[m2] = M2G_XK;
						M2gps_coor.Y[m2] = M2G_YK;
						M2gps_coor.Z[m2] = M2G_ZK;

						check2_gps[m2] = M2g_R - M2g_swj;					//检测改正值正确与否,与BDS的改正值对比,注意：检测时要加入卫星钟差，以使对比与BDS的改正值是否一致,正确的应该和BDS是一致的;
						m2++;											//m为可利用GPS卫星数目
					}
				}

				//if(dg[1].prn[ii] >= 1 &&dg[1].prn[ii] < 33)
				//{
				//	M2g_swj = 0, M2g_R = 0;
				//	M2G_XK = 0, M2G_YK = 0, M2G_ZK = 0;
				//	GNSS_POS_MODULE(geph, dg, 1, M2X0, M2Y0, M2Z0, &M2g_swj, &M2g_R, &M2G_XK, &M2G_YK, &M2G_ZK, ii, 1);//dg后面的参数为站号,为了配合dg【】中的号;
				//	if (M2g_swj != 0 && M2g_R != 0)
				//	{
				//		M2gps_wj[m2] = M2g_swj;
				//		M2GPS_SR[m2] = M2g_R;
				//		M2GPRN[m2] = dg[1].prn[ii];
				//		M2gps_coor.X[m2] = M2G_XK;
				//		M2gps_coor.Y[m2] = M2G_YK;
				//		M2gps_coor.Z[m2] = M2G_ZK;

				//		check2_gps[m2] = M2g_R - M2g_swj;					//检测改正值正确与否,与BDS的改正值对比,注意：检测时要加入卫星钟差，以使对比与BDS的改正值是否一致,正确的应该和BDS是一致的;
				//		m2++;											//m为可利用GPS卫星数目
				//	}
				//}
				if(dg[1].prn[ii] >= 33 && dg[1].prn[ii] < 57)//glonass 160814河北
				{
					M2r_swj = 0, M2r_R = 0;
					M2R_XK = 0, M2R_YK = 0, M2R_ZK = 0;
					int prn_satellite = dg[1].prn[ii];
					if (geph[prn_satellite].a[8] == 1)//卫星不健康
						continue;
					if (geph[prn_satellite].a[5] == 0.0||geph[prn_satellite].a[9] == 0.0||geph[prn_satellite].a[13] == 0.0)
						continue;

					double  tc=0,tc1=0;
					gtime_t glo_t;
					glo_t.time=geph[prn_satellite].a[0];
					glo_t.sec =geph[prn_satellite].a[1];
					gtime_t glo_ot = gpst2time(dg[1].tg.week, dg[1].tg.second);
					double svclk=GetSVpos_GLO(glo_t,glo_ot,dg[1].data[ii][0],geph[prn_satellite].a,M2X0,M2Y0,M2Z0,&M2R_XK, &M2R_YK, &M2R_ZK,tc);

					if(svclk > 10.0)
						continue;

					M2r_R=sqrt(pow(M2R_XK-M2X0,2)+pow(M2R_YK-M2Y0,2)+pow(M2R_ZK-M2Z0,2));//卫地距

					double rs[3]={0.0},rr[3]={0.0},r2suv[3]={0},pos[3]={0},azel[2]={0};
					double EL = 0;
					rs[0]=M2R_XK;
					rs[1]=M2R_YK;
					rs[2]=M2R_ZK;
					rr[0]=M2X0;
					rr[1]=M2Y0;
					rr[2]=M2Z0;
					geodist(rs,rr,r2suv);
					ecef2pos(rr,pos);
					EL=satazel(pos,r2suv,azel);
					if(fabs(EL*R2D)>15.0)//判断卫星高度角
					{
						M2r_swj = dg[1].data[ii][0] + svclk*299792458.0 ;//伪距
					}
					else							//高度角为10度((PI/18=0.17453292519943))，小于10的卫星舍去  15度 PI/12=0.2617993877991
					{
						M2r_R = 0;
						M2r_swj = 0;
						M2R_XK = 0;
						M2R_YK = 0;
						M2R_ZK = 0;
					}
					if (M2r_swj != 0 && M2r_R != 0)
					{
						M2glo_wj[r2] = M2r_swj;
						M2GLO_SR[r2] = M2r_R;
						M2RPRN[r2] = dg[1].prn[ii];
						M2glo_coor.X[r2] = M2R_XK;
						M2glo_coor.Y[r2] = M2R_YK;
						M2glo_coor.Z[r2] = M2R_ZK;

						check2_glo[r2] = M2r_R - M2r_swj;					//检测改正值正确与否,与GLO的改正值对比,注意：检测时要加入卫星钟差，以使对比与BDS的改正值是否一致,正确的应该和BDS是一致的;
						r2++;	
					}
				}
				//if(dg[1].prn[ii] >= 33 && dg[1].prn[ii] < 57)//glonass 160814河北
				//{
				//	//continue;
				//	M2r_swj = 0, M2r_R = 0;
				//	double rs[6];
				//	memset(rs,0x00,sizeof(rs));
				//	GLONASS_POS_MODULE(geph,dg,1,M2X0,M2Y0,M2Z0,&M2r_swj,&M2r_R,rs,ii);//glonass
				//	if (M2r_swj != 0 && M2r_R != 0)
				//	{
				//		M2glo_wj[r2] = M2r_swj;
				//		M2GLO_SR[r2] = M2r_R;
				//		M2RPRN[r2] = dg[1].prn[ii];
				//		M2glo_coor.X[r2] = rs[0];
				//		M2glo_coor.Y[r2] = rs[1];
				//		M2glo_coor.Z[r2] = rs[2];

				//		check2_glo[r2] = M2r_R - M2r_swj;					//检测改正值正确与否,与GLO的改正值对比,注意：检测时要加入卫星钟差，以使对比与BDS的改正值是否一致,正确的应该和BDS是一致的;
				//		r2++;	
				//	}
				//}

				if(dg[1].prn[ii] >= 161 && dg[1].prn[ii] < 181)
				{
					M2b_swj = 0, M2b_R = 0;
					M2B_XK = 0, M2B_YK = 0, M2B_ZK = 0;
					int prn_satellite = dg[1].prn[ii];
					if (geph[prn_satellite].a[24] == 1)//卫星不健康
						continue;
					double svclk=0.0;
					if(prn_satellite>165)
					{
						svclk=GetSVpos_BDS(dg[1].tg.week,dg[1].tg.second-14,geph[prn_satellite].a,M2X0,M2Y0,M2Z0,&M2B_XK,&M2B_YK, &M2B_ZK); 
						if(svclk > 10.0)
							continue;
					}
					else if(prn_satellite<=165)
					{
						svclk=GetSVpos_GEO(dg[1].tg.week,dg[1].tg.second-14,geph[prn_satellite].a,M2X0,M2Y0,M2Z0,&M2B_XK,&M2B_YK, &M2B_ZK);
						if(svclk > 10.0)
							continue;
					}

					M2b_R=sqrt(pow(M2B_XK-M2X0,2)+pow(M2B_YK-M2Y0,2)+pow(M2B_ZK-M2Z0,2));//卫地距

					double rs[3]={0.0},rr[3]={0.0},r2suv[3]={0},pos[3]={0},azel[2]={0};
					double EL = 0;
					rs[0]=M2B_XK;
					rs[1]=M2B_YK;
					rs[2]=M2B_ZK;
					rr[0]=M2X0;
					rr[1]=M2Y0;
					rr[2]=M2Z0;
					geodist(rs,rr,r2suv);
					ecef2pos(rr,pos);
					EL=satazel(pos,r2suv,azel);
					if(fabs(EL*R2D)>15.0)//判断卫星高度角
					{
						M2b_swj = dg[1].data[ii][0] + svclk*299792458.0 ;//伪距
					}
					else							//高度角为10度((PI/18=0.17453292519943))，小于10的卫星舍去  15度 PI/12=0.2617993877991
					{
						M2b_R = 0;
						M2b_swj = 0;
						M2B_XK = 0;
						M2B_YK = 0;
						M2B_ZK = 0;
					}
					if (M2b_swj != 0 && M2b_R != 0)
					{
						M2bds_wj[k2] = M2b_swj;
						M2BDS_SR[k2] = M2b_R;
						M2BPRN[k2] = dg[1].prn[ii];
						M2bds_coor.X[k2] = M2B_XK;
						M2bds_coor.Y[k2] = M2B_YK;
						M2bds_coor.Z[k2] = M2B_ZK;

						check2_bds[k2] = M2b_R - M2b_swj;			//检测改正值正确与否,与GPS的改正值对比,注意：检测时要加入卫星钟差，以使对比与GPS的改正值是否一致,正确的应该和GPS是一致的;
						k2++;								//m为可利用GPS卫星数目
					}
				}
				//if(dg[1].prn[ii] >= 161 && dg[1].prn[ii] < 181)
				//{
				//	//continue;
				//	M2b_swj = 0, M2b_R = 0;
				//	M2B_XK = 0, M2B_YK = 0, M2B_ZK = 0;
				//	GNSS_POS_MODULE(geph, dg, 1, M2X0, M2Y0, M2Z0, &M2b_swj, &M2b_R, &M2B_XK, &M2B_YK, &M2B_ZK, ii, 2);//dg后面的参数为站号,为了配合dg【】中的号;
				//	if (M2b_swj != 0 && M2b_R != 0)
				//	{
				//		M2bds_wj[k2] = M2b_swj;
				//		M2BDS_SR[k2] = M2b_R;
				//		M2BPRN[k2] = dg[1].prn[ii];
				//		M2bds_coor.X[k2] = M2B_XK;
				//		M2bds_coor.Y[k2] = M2B_YK;
				//		M2bds_coor.Z[k2] = M2B_ZK;

				//		check2_bds[k2] = M2b_R - M2b_swj;			//检测改正值正确与否,与GPS的改正值对比,注意：检测时要加入卫星钟差，以使对比与GPS的改正值是否一致,正确的应该和GPS是一致的;
				//		k2++;								//m为可利用GPS卫星数目
				//	}
				//}
			}


			/********▼匹配伪距改正数▼********/;
			int mm2 = 0, kk2 = 0, rr2 = 0;							//该历元中流动站和改正数相匹配的数;
			for (int ii = 0; ii<m2; ii++)				//匹配从3个基准站传过来的通过反距离加权后的GPS伪距改正值;
			{
				for (int jj = 0; jj<nn1; jj++)
				{
					//if (M2GPRN[ii]==BPC.G_PRN[jj]&&BPC.C_PRN[jj]!=bad_BPRN[0]&&BPC.C_PRN[jj]!=bad_BPRN[1]&&BPC.C_PRN[jj]!=bad_BPRN[2]&&BPC.C_PRN[jj]!=bad_BPRN[3]&&BPC.C_PRN[jj]!=bad_BPRN[4])
					if (M2GPRN[ii] == BPC.G_PRN[jj])
					{
						M2_gps_wj[mm2] = M2gps_wj[ii] + BPC.GPC[jj];
						M2_GPS_SR[mm2] = M2GPS_SR[ii];
						M2_GPRN[mm2] = M2GPRN[ii];
						M2_gps_coor.X[mm2] = M2gps_coor.X[ii];
						M2_gps_coor.Y[mm2] = M2gps_coor.Y[ii];
						M2_gps_coor.Z[mm2] = M2gps_coor.Z[ii];
						mm2++;
						break;
					}
				}
			}
			for (int ii = 0; ii<k2; ii++)				//匹配从3个基准站传过来的的通过反距离加权后的BDS伪距改正值;
			{
				for (int jj = 0; jj<pp; jj++)
				{
					//if (M2BPRN[ii]==BPC.C_PRN[jj]&&BPC.C_PRN[jj]!=bad_BPRN[0]&&BPC.C_PRN[jj]!=bad_BPRN[1]&&BPC.C_PRN[jj]!=bad_BPRN[2]&&BPC.C_PRN[jj]!=bad_BPRN[3]&&BPC.C_PRN[jj]!=bad_BPRN[4])
					if (M2BPRN[ii] == BPC.C_PRN[jj])
					{
						M2_bds_wj[kk2] = M2bds_wj[ii] + BPC.CPC[jj];
						M2_BDS_SR[kk2] = M2BDS_SR[ii];
						M2_BPRN[kk2] = M2BPRN[ii];
						M2_bds_coor.X[kk2] = M2bds_coor.X[ii];
						M2_bds_coor.Y[kk2] = M2bds_coor.Y[ii];
						M2_bds_coor.Z[kk2] = M2bds_coor.Z[ii];
						kk2++;
						break;
					}
				}
			}
			for (int ii = 0; ii<r2; ii++)				//匹配从n个基准站传过来的的通过反距离加权后的GLO伪距改正值;160814
			{
				for (int jj = 0; jj<rr; jj++)
				{
					if (M2RPRN[ii] == BPC.R_PRN[jj])
					{
						M2_glo_wj[rr2] = M2glo_wj[ii] + BPC.RPC[jj];
						M2_GLO_SR[rr2] = M2GLO_SR[ii];
						M2_RPRN[rr2] = M2RPRN[ii];
						M2_glo_coor.X[rr2] = M2glo_coor.X[ii];
						M2_glo_coor.Y[rr2] = M2glo_coor.Y[ii];
						M2_glo_coor.Z[rr2] = M2glo_coor.Z[ii];
						rr2++;
						break;
					}
				}
			}

			/************▼定位解算▼↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
			MM2 = mm2, KK2 = kk2, RR2 = rr2;
			ALL_GB2 = MM2 + KK2 + RR2;
			if (ALL_GB2 > 6 && MM2>0 && KK2>0 && RR2>0)//gps/bds/glonass三系统160814
			{
				gps_bds_glo_coor(&rcoor2,M2_gps_coor, M2_gps_wj, M2_GPS_SR, M2_bds_coor, M2_bds_wj, M2_BDS_SR,M2_glo_coor,M2_glo_wj,M2_GLO_SR,ALL_GB2, MM2, KK2, RR2, &GDOP2, &PDOP2, dg[1].tg.second);

				if (rcoor2.X != 0 && rcoor2.Y != 0 && rcoor2.Z != 0)
				{
					rcoor2.X = rcoor2.X + M2X0;			//新的接收机坐标=改正数+初值，下面判断，如果delt>0.001的话，返回do，将rcoor.X重新作为初值，循环计算到delt<0.001;
					rcoor2.Y = rcoor2.Y + M2Y0;
					rcoor2.Z = rcoor2.Z + M2Z0;
					//delt = rcoor2.X - M2X0;
					delt = sqrt(pow(rcoor2.X - M2X0,2.0)+pow(rcoor2.Y - M2Y0,2.0)+pow(rcoor2.Z - M2Z0,2.0));

					/*if (fabs(delt)<0.00001)
					break;*/
				}
				else
				{
					rcoor2.X = 0;
					rcoor2.Y = 0;
					rcoor2.Z = 0;
					rcoor2.P1 = 0;
					rcoor2.P2 = 0;
					rcoor2.P3 = 0;
					break;
				}
			}
			else if (ALL_GB2 > 5 && MM2>0 && KK2>0 && RR2==0)//GPS/BDS双系统
			{
				recei_coor(&rcoor2, M2_gps_coor, M2_gps_wj, M2_GPS_SR, M2_bds_coor, M2_bds_wj, M2_BDS_SR, ALL_GB2, MM2, KK2, &GDOP2, &PDOP2, dg[1].tg.second);//计算接收机坐标,返回位置的改正数rcoor.X、rcoor.Y、rcoor.Z;
				if (rcoor2.X != 0 && rcoor2.Y != 0 && rcoor2.Z != 0)
				{
					rcoor2.X = rcoor2.X + M2X0;			//新的接收机坐标=改正数+初值，下面判断，如果delt>0.001的话，返回do，将rcoor.X重新作为初值，循环计算到delt<0.001;
					rcoor2.Y = rcoor2.Y + M2Y0;
					rcoor2.Z = rcoor2.Z + M2Z0;
					//delt = rcoor2.X - M2X0;
					delt = sqrt(pow(rcoor2.X - M2X0,2.0)+pow(rcoor2.Y - M2Y0,2.0)+pow(rcoor2.Z - M2Z0,2.0));

					/*if (fabs(delt)<0.00001)
					break;*/
				}
				else
				{
					rcoor2.X = 0;
					rcoor2.Y = 0;
					rcoor2.Z = 0;
					rcoor2.P1 = 0;
					rcoor2.P2 = 0;
					break;
				}
			}
			else if (MM2 >= 4 && KK2==0&& RR2==0)//单GPS系统，大于4时，RMS才有值;
			{
				recei_coor_single(&rcoor2,M2_gps_coor,M2_gps_wj,&MM2,M2_GPS_SR,&GDOP2,&PDOP2);//计算接收机坐标,返回位置的改正数rcoor.X、rcoor.Y、rcoor.Z;
				if(rcoor2.X==0&&rcoor2.Y==0&&rcoor2.Z==0)//不能循环太多，比如循环39次，这里的rcoor.X==0&&rcoor.Y==0&&rcoor.Z==0，但是是正确的
				{
					rcoor2.X = 0;
					rcoor2.Y = 0;
					rcoor2.Z = 0;
					rcoor2.P1 = 0;
					rcoor2.P2 = 0;
					break;
				}
				else
				{
					rcoor2.X = rcoor2.X + M2X0;			//新的接收机坐标=改正数+初值，下面判断，如果delt>0.001的话，返回do，将rcoor.X重新作为初值，循环计算到delt<0.001;
					rcoor2.Y = rcoor2.Y + M2Y0;
					rcoor2.Z = rcoor2.Z + M2Z0;
					//delt = rcoor2.X - M2X0;
					delt = sqrt(pow(rcoor2.X - M2X0,2.0)+pow(rcoor2.Y - M2Y0,2.0)+pow(rcoor2.Z - M2Z0,2.0));

					/*	if (fabs(delt)<0.00001)
					break;*/

				}
			}
			else if (MM2 ==0 && KK2>=4&& RR2==0)//单BDS系统，大于4时，RMS才有值;
			{
				recei_coor_single(&rcoor2,M2_bds_coor,M2_bds_wj,&KK2,M2_BDS_SR,&GDOP2,&PDOP2);//计算接收机坐标,返回位置的改正数rcoor.X、rcoor.Y、rcoor.Z;
				if(rcoor2.X==0&&rcoor2.Y==0&&rcoor2.Z==0)//不能循环太多，比如循环39次，这里的rcoor.X==0&&rcoor.Y==0&&rcoor.Z==0，但是是正确的
				{
					rcoor2.X = 0;
					rcoor2.Y = 0;
					rcoor2.Z = 0;
					rcoor2.P1 = 0;
					rcoor2.P2 = 0;
					break;
				}
				else
				{
					rcoor2.X = rcoor2.X + M2X0;			//新的接收机坐标=改正数+初值，下面判断，如果delt>0.001的话，返回do，将rcoor.X重新作为初值，循环计算到delt<0.001;
					rcoor2.Y = rcoor2.Y + M2Y0;
					rcoor2.Z = rcoor2.Z + M2Z0;
					//delt = rcoor2.X - M2X0;
					delt = sqrt(pow(rcoor2.X - M2X0,2.0)+pow(rcoor2.Y - M2Y0,2.0)+pow(rcoor2.Z - M2Z0,2.0));

					/*if (fabs(delt)<0.00001)
					break;*/

				}
			}
			else
			{
				rcoor2.X = 0;
				rcoor2.Y = 0;
				rcoor2.Z = 0;
				rcoor2.P1 = 0;
				rcoor2.P2 = 0;
				break;
			}
			//if (rcoor2.X!=0&&fabs(delt)<0.00001)
			//	break;
		}while(delt>0.00001);
		rp rcoor_raim=rcoor2;
		int MM_raim=MM2,KK_raim=KK2,RR_raim=RR2;
		double GDOP_raim=0.0,PDOP_raim=0.0;
		int chaoxian_num = 0;								//监测站监测卫星，监测有几个超限卫星chaoxian_num;
		int bad_GPRN[20] = { 0 }, bad_BPRN[20] = { 0 }, bad_RPRN[20] = { 0 };		//存储坏的GPS卫星和坏的BDS卫星;
		int B_bad_num = 0, G_bad_num = 0, R_bad_num = 0;								//BDS、GPS残差超限的个数;
		int T = MM_raim + KK_raim + RR_raim;						//多系统定位总的卫星个数Totle;
		//int i1, j1;									//为了进行循环;
		int final_N, final_P, final_R;
		double X_raim0, Y_raim0, Z_raim0;
		X_raim0 = rcoor_raim.X;
		Y_raim0 = rcoor_raim.Y;
		Z_raim0 = rcoor_raim.Z;

		/************▼完备性监测▼↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*///160814
		int COL = 6;
		double	*ll = new	double[T]();		//课本P57参数  等加以double	(*ll)[1]=	 new	double[T][1];
		double	*mm = new	double[T]();
		double	*nn = new	double[T]();
		double	*L = new	double[T]();
		double	*A = new	double[T * COL]();		//状态矩阵A;
		double	*AT = new	double[COL * T]();		//状态矩阵A的转置;
		double	*P = new	double[T*T]();		//权矩阵P;              ()是对动态内存进行初始化
		double	*ATP = new	double[COL * T]();		//A的转置乘以P;
		double	*ATPA = new	double[COL * COL]();		//A的转置乘以P乘以A;
		double	*inv_ATPA = new	double[COL * COL]();		//(A的转置乘以P乘以A)的逆;
		double	*ATPL = new	double[COL]();		//A的转置乘以P乘以L;
		double	*result = new	double[COL]();		//(A的转置乘以P乘以A)乘以(A的转置乘以P乘以L)，(inv_ATPA)(ATPL);


		double	*AX = new	double[T]();		//A乘以X;
		double  *V = new	double[T]();		//V=AX-L
		double	*VT = new	double[1 * T]();
		double	*VTP = new	double[1 * T]();
		double	*VTPV = new	double[T * 1]();

		///////////////////////////////////////////列法方程;

		//cout<<"系数矩阵B和L"<<endl;																	//
		for (int i1 = 0; i1<MM_raim; i1++)//GPS
		{
			ll[i1] = (M2_gps_coor.X[i1] - rcoor_raim.X) / M2_GPS_SR[i1];
			mm[i1] = (M2_gps_coor.Y[i1] - rcoor_raim.Y) / M2_GPS_SR[i1];
			nn[i1] = (M2_gps_coor.Z[i1] - rcoor_raim.Z) / M2_GPS_SR[i1];
			A[i1 * COL + 0] = ll[i1];
			A[i1 * COL + 1] = mm[i1];
			A[i1 * COL + 2] = nn[i1];
			A[i1 * COL + 3] = -1;
			//A[i*COL+4]=0;								//初始化了就不需要了
			L[i1] = M2_GPS_SR[i1] - M2_gps_wj[i1];

			//printf("%8.3f%8.3f%8.3f%8.3f%8.3f%16.3f\n",A[i*5+0],A[i*5+1],A[i*5+2],A[i*5+3],A[i*5+4],L[i]);	//

			P[i1*T + i1] = 1;									//给GPS定的权
		}
		for (int j1 = MM_raim; j1<MM_raim+KK_raim; j1++)//BDS
		{
			ll[j1] = (M2_bds_coor.X[j1 - MM_raim] - rcoor_raim.X) / M2_BDS_SR[j1 - MM_raim];
			mm[j1] = (M2_bds_coor.Y[j1 - MM_raim] - rcoor_raim.Y) / M2_BDS_SR[j1 - MM_raim];
			nn[j1] = (M2_bds_coor.Z[j1 - MM_raim] - rcoor_raim.Z) / M2_BDS_SR[j1 - MM_raim];
			A[j1 * COL + 0] = ll[j1];
			A[j1 * COL + 1] = mm[j1];
			A[j1 * COL + 2] = nn[j1];
			//A[j*COL+3]=0;								//初始化了就不需要了;
			A[j1 * COL + 4] = -1;
			L[j1] = M2_BDS_SR[j1 - MM_raim] - M2_bds_wj[j1 - MM_raim];

			//printf("%8.3f%8.3f%8.3f%8.3f%8.3f%16.3f\n",A[j*5+0],A[j*5+1],A[j*5+2],A[j*5+3],A[j*5+4],L[j]);	//

			P[j1*T + j1] = 1;									//给BDS定的权
		}
		int nGPSBDS_raim = MM_raim+KK_raim;
		for (int j1 = nGPSBDS_raim; j1<T; j1++)//GLONASS
		{
			ll[j1] = (M2_glo_coor.X[j1 - nGPSBDS_raim] - rcoor_raim.X) / M2_GLO_SR[j1 - nGPSBDS_raim];
			mm[j1] = (M2_glo_coor.Y[j1 - nGPSBDS_raim] - rcoor_raim.Y) / M2_GLO_SR[j1 - nGPSBDS_raim];
			nn[j1] = (M2_glo_coor.Z[j1 - nGPSBDS_raim] - rcoor_raim.Z) / M2_GLO_SR[j1 - nGPSBDS_raim];
			A[j1 * COL + 0] = ll[j1];
			A[j1 * COL + 1] = mm[j1];
			A[j1 * COL + 2] = nn[j1];
			//A[j*COL+3]=0;								//初始化了就不需要了;
			A[j1 * COL + 5] = -1;
			L[j1] = M2_GLO_SR[j1 - nGPSBDS_raim] - M2_glo_wj[j1 - nGPSBDS_raim];

			//printf("%8.3f%8.3f%8.3f%8.3f%8.3f%16.3f\n",A[j*5+0],A[j*5+1],A[j*5+2],A[j*5+3],A[j*5+4],L[j]);	//

			P[j1*T + j1] = 1;									//给GLO定的权
		}

		int aCol=0;
		///////////////////////////////////////////通过函数的指针进行矩阵的运算，传出需要的矩阵;
		if(MM_raim>0&&KK_raim>0&&RR_raim>0)//gps/bds/glonass
		{
			aCol = 6;
			M_Tra(T, 6, A, AT);							//矩阵转置	A的转置		传出AT;
			M_Mul(6, T, T, AT, P, ATP);						//矩阵相乘	AT乘P		传出ATP;
			M_Mul(6, T, 6, ATP, A, ATPA);					//			ATP乘A		传出ATPA;
			M_Inv(6, ATPA, inv_ATPA);						//矩阵求逆	ATPA的逆		传出inv_ATPA;
			M_Mul(6, T, 1, ATP, L, ATPL);					//			ATP乘L		传出ATPL;
			M_Mul(6, 6, 1, inv_ATPA, ATPL, result);			//			inv_ATPA乘ATPL传出result;
		}
		else if(MM_raim>0&&KK_raim>0&&RR_raim==0)//gps/bds
		{
			aCol = 5;
			M_Tra(T, 5, A, AT);							//矩阵转置	A的转置		传出AT;
			M_Mul(5, T, T, AT, P, ATP);						//矩阵相乘	AT乘P		传出ATP;
			M_Mul(5, T, 5, ATP, A, ATPA);					//			ATP乘A		传出ATPA;
			M_Inv(5, ATPA, inv_ATPA);						//矩阵求逆	ATPA的逆		传出inv_ATPA;
			M_Mul(5, T, 1, ATP, L, ATPL);					//			ATP乘L		传出ATPL;
			M_Mul(5, 5, 1, inv_ATPA, ATPL, result);			//			inv_ATPA乘ATPL传出result;
		}
		else if(MM_raim>0&&KK_raim==0&&RR_raim==0)//gps
		{
			aCol = 4;
			M_Tra(T, 4, A, AT);							//矩阵转置	A的转置		传出AT;
			M_Mul(4, T, T, AT, P, ATP);						//矩阵相乘	AT乘P		传出ATP;
			M_Mul(4, T, 4, ATP, A, ATPA);					//			ATP乘A		传出ATPA;
			M_Inv(4, ATPA, inv_ATPA);						//矩阵求逆	ATPA的逆		传出inv_ATPA;
			M_Mul(4, T, 1, ATP, L, ATPL);					//			ATP乘L		传出ATPL;
			M_Mul(4, 4, 1, inv_ATPA, ATPL, result);			//			inv_ATPA乘ATPL传出result;
		}
		else
		{
			return;
		}

		//cout<<inv_ATPA[1]<<inv_ATPA[2]<<inv_ATPA[3]<<inv_ATPA[4]<<inv_ATPA[5]<<endl;
		//cout<<ATPL[1]<<ATPL[2]<<ATPL[3]<<ATPL[4]<<ATPL[5]<<endl;
		if (inv_ATPA != NULL)
		{
			rcoor_raim.X = result[0];
			rcoor_raim.Y = result[1];
			rcoor_raim.Z = result[2];
			rcoor_raim.P1 = result[3];
			rcoor_raim.P2 = result[4];
			rcoor_raim.P3 = result[5];

			for (int i = 0; i<aCol; i++)
				GDOP_raim += inv_ATPA[i * aCol + i];
			sate_num.GDOP_raim = sqrt(GDOP_raim);
			for (int i = 0; i<3; i++)
				PDOP_raim += inv_ATPA[i * aCol + i];
			sate_num.PDOP_raim = sqrt(PDOP_raim);
		}
		else
		{
			rcoor_raim.X = 0;
			rcoor_raim.Y = 0;
			rcoor_raim.Z = 0;
			rcoor_raim.P1 = 0;
			rcoor_raim.P2 = 0;
			rcoor_raim.P3 = 0;
			//printf("这个历元数据无法求解!\n");
			//system("pause");
		}

		double X[6][1];
		X[0][0] = rcoor_raim.X;
		X[0][1] = rcoor_raim.Y;
		X[0][2] = rcoor_raim.Z;
		X[0][3] = rcoor_raim.P1;
		X[0][4] = rcoor_raim.P2;
		X[0][5] = rcoor_raim.P3;
		//double	*AX=	new	double[T]();			//A乘以X;
		M_Mul(T,aCol, 1, A, X[0], AX);							//矩阵相乘;
		//double  *V=		new	double[T]();			//V=AX-L

		for (int p = 0; p<T; p++)
		{
			V[p] = AX[p] - L[p];
		}
		//double *VT=		new	double[1*T]();
		//double *VTP=	new	double[1*T]();
		//double *VTPV=	new	double[T*1]();

		M_Tra(T, 1, V, VT);								//矩阵转置	A的转置		传出AT;
		M_Mul(1, T, T, VT, P, VTP);							//矩阵相乘	AT乘P		传出ATP;
		M_Mul(1, T, 1, VTP, V, VTPV);
		double RMS_raim = sqrt(*VTPV / (T - aCol));
		double w[32];
		for (int i = 0; i<T; i++)
		{
			w[i] = fabs(V[i]) / (RMS_raim*sqrt((T - 1.0) / T));
			//printf("%16.8f\n",w[i]);				//
		}
		int n_s=0;
		int NNN,PPP,RRR;
		int chaoxuanNoOk=0;
		for(int i=0;i<T;i++)
		{
			if(w[i]> 3)
			{
				chaoxuanNoOk++;
				//w1=w[i];
				n_s=i;
				NNN = MM_raim;
				PPP = KK_raim;
				RRR = RR_raim;
				if (n_s>NNN+PPP - 1)			//说明是GLO卫星的 160814
				{
					bad_RPRN[chaoxian_num] = M2_RPRN[n_s - NNN-PPP];//如果GPS7颗，BDS9颗，现在pp=8，也就是w中第9个，那么就是BDS卫星的第2个对应于1，即8-7=1;
					//chaoxian_num++;
					//for(int j=1;j<5;j++)//四个基准站，依次消除坏星;
					//{
					for (int m=0;m<VBPC[IWGD].R_num;m++)//从0开始依次比对prn
					{
						if (bad_RPRN[chaoxian_num]==VBPC[IWGD].R_PRN[m])//当prn相同时就消除这颗卫星对应的内容;
						{
							for (int s = m; s<VBPC[IWGD].R_num; s++)//从坏星开始将后一个星内容覆盖前一个卫星内容;
							{
								VBPC[IWGD].R_PRN[s]=VBPC[IWGD].R_PRN[s+1];
								VBPC[IWGD].RPC[s]=VBPC[IWGD].RPC[s+1];
							}
							VBPC[IWGD].R_num--;
							break;
						}
					}
					//}
					R_bad_num++;
					RR_raim = RRR - 1;		//新的GLO卫星个数
					chaoxian_num++;
				}
				else if (n_s>NNN-1&&n_s<=NNN+PPP-1)			//说明是BDS卫星的
				{
					bad_BPRN[chaoxian_num] = M2_BPRN[n_s - NNN];//如果GPS7颗，BDS9颗，现在pp=8，也就是w中第9个，那么就是BDS卫星的第2个对应于1，即8-7=1;
					//chaoxian_num++;
					//for(int j=1;j<5;j++)//四个基准站，依次消除坏星;
					//{
					for (int m=0;m<VBPC[IWGD].C_num;m++)//从0开始依次比对prn
					{
						if (bad_BPRN[chaoxian_num]==VBPC[IWGD].C_PRN[m])//当prn相同时就消除这颗卫星对应的内容;
						{
							for (int s = m; s<VBPC[IWGD].C_num; s++)//从坏星开始将后一个星内容覆盖前一个卫星内容;
							{
								VBPC[IWGD].C_PRN[s]=VBPC[IWGD].C_PRN[s+1];
								VBPC[IWGD].CPC[s]=VBPC[IWGD].CPC[s+1];
							}
							VBPC[IWGD].C_num--;
							break;
						}
					}
					//}
					B_bad_num++;
					KK_raim = PPP - 1;		//新的BDS卫星个数
					chaoxian_num++;
				}
				else					//说明是GPS卫星的
				{
					bad_GPRN[chaoxian_num] = M2_GPRN[n_s];
					//for(int j=1;j<5;j++)//四个基准站，依次消除坏星;
					//	{
					for (int m=0;m<VBPC[IWGD].G_num;m++)//从0开始依次比对prn
					{
						if (bad_GPRN[chaoxian_num]==VBPC[IWGD].G_PRN[m])//当prn相同时就消除这颗卫星对应的内容;
						{
							for (int s = m; s<VBPC[IWGD].G_num; s++)//从坏星开始将后一个星内容覆盖前一个卫星内容;
							{
								VBPC[IWGD].G_PRN[s]=VBPC[IWGD].G_PRN[s+1];
								VBPC[IWGD].GPC[s]=VBPC[IWGD].GPC[s+1];
							}
							VBPC[IWGD].G_num--;
							break;
						}
					}
					//}
					G_bad_num++;
					MM_raim = NNN - 1;		//新的GPS卫星个数
					chaoxian_num++;
				}
			}
		}		
		if(chaoxuanNoOk!=0)
		{
			NWDGNSS_3SYS_MOVING_POS_MODULE(GridValue,M_coor,VBPC, dg[1],geph,rcoor2,sate_num);//再次计算;
		}
		else
		{
			sate_num.MM2 = MM_raim;
			sate_num.KK2 = KK_raim;
			sate_num.RR2 = RR_raim;
			sate_num.ALL_GB2 = ALL_GB2;
			sate_num.delX2 = rcoor2.X;
			sate_num.delY2 = rcoor2.Y;
			sate_num.delZ2 = rcoor2.Z;
			sate_num.M2_P1 = rcoor2.P1;
			sate_num.M2_P2 = rcoor2.P2;
			sate_num.M2_P3 = rcoor2.P3;
			sate_num.GDOP2 = GDOP2;
			sate_num.PDOP2 = PDOP2;
		}
		delete  []ll;
		delete	[]mm;
		delete	[]nn;
		delete	[]L;
		delete	[]A;
		delete	[]AT;
		delete	[]P;	
		delete	[]ATP;
		delete	[]ATPA;
		delete	[]inv_ATPA;
		delete	[]ATPL;
		delete	[]result;
		delete	[]AX;
		delete  []V;	
		delete	[]VT;
		delete	[]VTP;
		delete	[]VTPV;
	}

}
int CNDGNSS::NWDGNSS_3SYS_MONITOR_POS_MODULE_RAIM(GridAttribute GridValue,VBS_PR_CR VBPC[], DATG dg0[], GEPH geph[], IOFH ih0[],Sate_NUM sate_num[])
{
	//利用流动站单点定位结果判断所在网格并利用伪距改正数;

	if (GridValue.Monitor_BS_ID<=0) return -1;//该网格点没有符合监控站要求的站;
	if (GridValue.Grid_ID > GRIDNUM) return -1;//该网格点没有符合监控站要求的站;
	if (fabs(VBPC[GridValue.Grid_ID].tg.second-dg0[GridValue.Monitor_BS_ID].tg.second)>5)//该网格点改正数适用历元与监控站历元不符20150807;
	{
		VBPC[GridValue.Grid_ID].G_num=0;//卫星数设为0;
		VBPC[GridValue.Grid_ID].C_num=0;
		VBPC[GridValue.Grid_ID].R_num=0;
		return -1;
	}
	rp rcoor2={0};
	double	delt = 1;								//do...while()限制条件中的接收机X坐标迭代控制条件
	double	GDOP2 = 0, PDOP2 = 0;
	DATG dg[5] = { 0 };
	//int i = 0;
	dg[1] = dg0[GridValue.Monitor_BS_ID];
	BS_PR_CR BPC={0};

	IOFH ih3[4] = { 0 };
	int IWGD=GridValue.Grid_ID;//网格点ID;

	int pp=0;
	int nn1=0;
	int rr=0;
	if(IWGD<=GRIDNUM)
	{
		for(int n1 = 0 ;n1 < VBPC[IWGD].G_num; n1++)
		{
			BPC.G_PRN[n1] = VBPC[IWGD].G_PRN[n1];
			BPC.GPC[n1] = VBPC[IWGD].GPC[n1];
		}

		for(int p1 = 0 ;p1 < VBPC[IWGD].C_num; p1++)
		{
			BPC.C_PRN[p1] = VBPC[IWGD].C_PRN[p1];
			BPC.CPC[p1] = VBPC[IWGD].CPC[p1];
		}
		for(int r1 = 0 ;r1 < VBPC[IWGD].R_num; r1++)
		{
			BPC.R_PRN[r1] = VBPC[IWGD].R_PRN[r1];
			BPC.RPC[r1] = VBPC[IWGD].RPC[r1];
		}
		pp=VBPC[IWGD].C_num;
		nn1=VBPC[IWGD].G_num;
		rr=VBPC[IWGD].R_num;
	}
	else
	{
		return -1;
	}


	/************▼监控站▼↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/

	double	M2X0, M2Y0, M2Z0;							//流动站初始坐标;
	double	M2g_swj, M2g_R, M2b_swj, M2b_R, M2r_swj, M2r_R;
	double	M2G_XK, M2G_YK, M2G_ZK, M2B_XK, M2B_YK, M2B_ZK;	//初始坐标;
	int		MM2, KK2, RR2,ALL_GB2;
	//rp		rcoor2={0};
	int chaoxian_num = 0;						//监测站监测卫星，监测有几个超限卫星chaoxian_num;
	rcoor2.X = ih0[GridValue.Monitor_BS_ID].xyz[0];//用精确坐标做初始坐标;
	rcoor2.Y = ih0[GridValue.Monitor_BS_ID].xyz[1];
	rcoor2.Z = ih0[GridValue.Monitor_BS_ID].xyz[2];

	int bad_GPRN[40] = { 0 }, bad_BPRN[40] = { 0 }, bad_RPRN[40] = { 0 };	//存储坏的GPS卫星和坏的BDS卫星;



	double	M2gps_wj[40] = { 0 }, M2GPS_SR[40] = { 0 };	//流动站解算的gps伪距&近似距离——存储值;
	double	M2bds_wj[40] = { 0 }, M2BDS_SR[40] = { 0 };	//流动站解算的bds伪距&近似距离——存储值;
	double	M2glo_wj[40] = { 0 }, M2GLO_SR[40] = { 0 };	//流动站解算的bds伪距&近似距离——存储值;
	int		M2GPRN[40] = { 0 };						//流动站gpsPRN号——存储值;
	int		M2BPRN[40] = { 0 };						//流动站bdsPRN号——存储值;
	int		M2RPRN[40] = { 0 };						//流动站bdsPRN号——存储值;
	sp		M2gps_coor = { 0 }, M2bds_coor = { 0 }, M2glo_coor = { 0 };		//流动站解算的gps与bds的卫星坐标——存储值;

	double	M2_gps_wj[40] = { 0 }, M2_GPS_SR[40] = { 0 };//流动站最终解算;
	double	M2_bds_wj[40] = { 0 }, M2_BDS_SR[40] = { 0 };//流动站最终解算;
	double	M2_glo_wj[40] = { 0 }, M2_GLO_SR[40] = { 0 };//流动站最终解算;
	int		M2_GPRN[40] = { 0 };					//流动站最终解算;
	int		M2_BPRN[40] = { 0 };					//流动站最终解算;
	int		M2_RPRN[40] = { 0 };					//流动站最终解算;
	sp		M2_gps_coor = { 0 }, M2_bds_coor = { 0 }, M2_glo_coor = { 0 };	//流动站最终解算;

	int xunhuan=0;
	do		//最多循环10次跳出，代替do。。。。while;
	{ 


		if( xunhuan>14)	{break;}		//最多循环10次跳出，代替do。。。。while;
		xunhuan++;

		double check2_gps[35] = { 0 }, check2_bds[35] = { 0 }, check2_glo[35] = { 0 };//检测伪距改正输出;
		int	m2 = 0, k2 = 0, r2 = 0;								//循环回代置零;
		M2X0 = rcoor2.X;								//用于循环回代;
		M2Y0 = rcoor2.Y;
		M2Z0 = rcoor2.Z;

		for (int ii = 0; ii<dg[1].nsat; ii++)				//基于流动站计算卫星位置及伪距&卫地距;
		{
			if(dg[1].prn[ii] >= 1 &&dg[1].prn[ii] < 33)
			{
				M2g_swj = 0, M2g_R = 0;
				M2G_XK = 0, M2G_YK = 0, M2G_ZK = 0;
				GNSS_POS_MODULE(geph, dg, 1, M2X0, M2Y0, M2Z0, &M2g_swj, &M2g_R, &M2G_XK, &M2G_YK, &M2G_ZK, ii, 1);//dg后面的参数为站号,为了配合dg【】中的号;
				if (M2g_swj != 0 && M2g_R != 0)
				{
					M2gps_wj[m2] = M2g_swj;
					M2GPS_SR[m2] = M2g_R;
					M2GPRN[m2] = dg[1].prn[ii];
					M2gps_coor.X[m2] = M2G_XK;
					M2gps_coor.Y[m2] = M2G_YK;
					M2gps_coor.Z[m2] = M2G_ZK;

					check2_gps[m2] = M2g_R - M2g_swj;					//检测改正值正确与否,与BDS的改正值对比,注意：检测时要加入卫星钟差，以使对比与BDS的改正值是否一致,正确的应该和BDS是一致的;
					m2++;											//m为可利用GPS卫星数目
				}
			}
			if(dg[1].prn[ii] >= 33 && dg[1].prn[ii] < 57)//glonass 160814
			{
				M2r_swj = 0, M2r_R = 0;
				double rs[6];
				memset(rs,0x00,sizeof(rs));
				GLONASS_POS_MODULE(geph,dg,1,M2X0,M2Y0,M2Z0,&M2r_swj,&M2r_R,rs,ii);//glonass
				if (M2r_swj != 0 && M2r_R != 0)
				{
					M2glo_wj[r2] = M2r_swj;
					M2GLO_SR[r2] = M2r_R;
					M2RPRN[r2] = dg[1].prn[ii];
					M2glo_coor.X[r2] = rs[0];
					M2glo_coor.Y[r2] = rs[1];
					M2glo_coor.Z[r2] = rs[2];

					check2_glo[r2] = M2r_R - M2r_swj;					//检测改正值正确与否,与GLO的改正值对比,注意：检测时要加入卫星钟差，以使对比与BDS的改正值是否一致,正确的应该和BDS是一致的;
					r2++;	
				}
			}
			if(dg[1].prn[ii] >= 161 && dg[1].prn[ii] < 181)
			{
				M2b_swj = 0, M2b_R = 0;
				M2B_XK = 0, M2B_YK = 0, M2B_ZK = 0;
				GNSS_POS_MODULE(geph, dg, 1, M2X0, M2Y0, M2Z0, &M2b_swj, &M2b_R, &M2B_XK, &M2B_YK, &M2B_ZK, ii, 2);//dg后面的参数为站号,为了配合dg【】中的号;
				if (M2b_swj != 0 && M2b_R != 0)
				{
					M2bds_wj[k2] = M2b_swj;
					M2BDS_SR[k2] = M2b_R;
					M2BPRN[k2] = dg[1].prn[ii];
					M2bds_coor.X[k2] = M2B_XK;
					M2bds_coor.Y[k2] = M2B_YK;
					M2bds_coor.Z[k2] = M2B_ZK;

					check2_bds[k2] = M2b_R - M2b_swj;			//检测改正值正确与否,与GPS的改正值对比,注意：检测时要加入卫星钟差，以使对比与GPS的改正值是否一致,正确的应该和GPS是一致的;
					k2++;								//m为可利用GPS卫星数目
				}
			}
		}

		/************▼匹配历元改正数▼↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
		int mm2 = 0, kk2 = 0, rr2 = 0;							//该历元中流动站和改正数相匹配的数;
		for (int ii = 0; ii<m2; ii++)				//匹配从n个基准站传过来的通过反距离加权后的GPS伪距改正值;
		{
			for (int jj = 0; jj<nn1; jj++)
			{
				//if (M2GPRN[ii]==BPC.G_PRN[jj]&&BPC.C_PRN[jj]!=bad_BPRN[0]&&BPC.C_PRN[jj]!=bad_BPRN[1]&&BPC.C_PRN[jj]!=bad_BPRN[2]&&BPC.C_PRN[jj]!=bad_BPRN[3]&&BPC.C_PRN[jj]!=bad_BPRN[4])
				if (M2GPRN[ii] == BPC.G_PRN[jj])
				{
					M2_gps_wj[mm2] = M2gps_wj[ii] + BPC.GPC[jj];
					M2_GPS_SR[mm2] = M2GPS_SR[ii];
					M2_GPRN[mm2] = M2GPRN[ii];
					M2_gps_coor.X[mm2] = M2gps_coor.X[ii];
					M2_gps_coor.Y[mm2] = M2gps_coor.Y[ii];
					M2_gps_coor.Z[mm2] = M2gps_coor.Z[ii];
					mm2++;
					break;
				}
			}
		}
		for (int ii = 0; ii<k2; ii++)				//匹配从n个基准站传过来的的通过反距离加权后的BDS伪距改正值;
		{
			for (int jj = 0; jj<pp; jj++)
			{
				//if (M2BPRN[ii]==BPC.C_PRN[jj]&&BPC.C_PRN[jj]!=bad_BPRN[0]&&BPC.C_PRN[jj]!=bad_BPRN[1]&&BPC.C_PRN[jj]!=bad_BPRN[2]&&BPC.C_PRN[jj]!=bad_BPRN[3]&&BPC.C_PRN[jj]!=bad_BPRN[4])
				if (M2BPRN[ii] == BPC.C_PRN[jj])
				{
					M2_bds_wj[kk2] = M2bds_wj[ii] + BPC.CPC[jj];
					M2_BDS_SR[kk2] = M2BDS_SR[ii];
					M2_BPRN[kk2] = M2BPRN[ii];
					M2_bds_coor.X[kk2] = M2bds_coor.X[ii];
					M2_bds_coor.Y[kk2] = M2bds_coor.Y[ii];
					M2_bds_coor.Z[kk2] = M2bds_coor.Z[ii];
					kk2++;
					break;
				}
			}
		}
		for (int ii = 0; ii<r2; ii++)				//匹配从n个基准站传过来的的通过反距离加权后的GLO伪距改正值;160814
		{
			for (int jj = 0; jj<rr; jj++)
			{
				if (M2RPRN[ii] == BPC.R_PRN[jj])
				{
					M2_glo_wj[rr2] = M2glo_wj[ii] + BPC.RPC[jj];
					M2_GLO_SR[rr2] = M2GLO_SR[ii];
					M2_RPRN[rr2] = M2RPRN[ii];
					M2_glo_coor.X[rr2] = M2glo_coor.X[ii];
					M2_glo_coor.Y[rr2] = M2glo_coor.Y[ii];
					M2_glo_coor.Z[rr2] = M2glo_coor.Z[ii];
					rr2++;
					break;
				}
			}
		}

		/************▼定位解算▼↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
		MM2 = mm2, KK2 = kk2, RR2 = rr2;
		ALL_GB2 = MM2 + KK2 + RR2;
		if (ALL_GB2 > 6 && MM2>0 && KK2>0 && RR2>0)//gps/bds/glonass三系统160814
		{
			gps_bds_glo_coor(&rcoor2,M2_gps_coor, M2_gps_wj, M2_GPS_SR, M2_bds_coor, M2_bds_wj, M2_BDS_SR,M2_glo_coor,M2_glo_wj,M2_GLO_SR,ALL_GB2, MM2, KK2, RR2, &GDOP2, &PDOP2, dg[1].tg.second);

			if (rcoor2.X != 0 && rcoor2.Y != 0 && rcoor2.Z != 0)
			{
				rcoor2.X = rcoor2.X + M2X0;			//新的接收机坐标=改正数+初值，下面判断，如果delt>0.001的话，返回do，将rcoor.X重新作为初值，循环计算到delt<0.001;
				rcoor2.Y = rcoor2.Y + M2Y0;
				rcoor2.Z = rcoor2.Z + M2Z0;
				//delt = rcoor2.X - M2X0;
				delt = sqrt(pow(rcoor2.X - M2X0,2.0)+pow(rcoor2.Y - M2Y0,2.0)+pow(rcoor2.Z - M2Z0,2.0));

				/*if (fabs(delt)<0.00001)
				break;*/
			}
			else
			{
				rcoor2.X = 0;
				rcoor2.Y = 0;
				rcoor2.Z = 0;
				rcoor2.P1 = 0;
				rcoor2.P2 = 0;
				rcoor2.P3 = 0;
				break;
			}
		}
		else if (ALL_GB2 > 5 && MM2>0 && KK2>0 && RR2==0)//GPS/BDS双系统;
		{
			recei_coor(&rcoor2, M2_gps_coor, M2_gps_wj, M2_GPS_SR, M2_bds_coor, M2_bds_wj, M2_BDS_SR, ALL_GB2, MM2, KK2, &GDOP2, &PDOP2, dg[1].tg.second);//计算接收机坐标,返回位置的改正数rcoor.X、rcoor.Y、rcoor.Z;
			if (rcoor2.X != 0 && rcoor2.Y != 0 && rcoor2.Z != 0)
			{
				rcoor2.X = rcoor2.X + M2X0;			//新的接收机坐标=改正数+初值，下面判断，如果delt>0.001的话，返回do，将rcoor.X重新作为初值，循环计算到delt<0.001;
				rcoor2.Y = rcoor2.Y + M2Y0;
				rcoor2.Z = rcoor2.Z + M2Z0;
				//delt = rcoor2.X - M2X0;
				delt = sqrt(pow(rcoor2.X - M2X0,2.0)+pow(rcoor2.Y - M2Y0,2.0)+pow(rcoor2.Z - M2Z0,2.0));

				/*if (fabs(delt)<0.00001)
				break;*/
			}
			else
			{
				rcoor2.X = 0;
				rcoor2.Y = 0;
				rcoor2.Z = 0;
				rcoor2.P1 = 0;
				rcoor2.P2 = 0;
				break;
			}
		}
		else if (MM2 >= 4 && KK2==0 && RR2==0)//单GPS系统，大于4时，RMS才有值;
		{
			recei_coor_single(&rcoor2,M2_gps_coor,M2_gps_wj,&MM2,M2_GPS_SR,&GDOP2,&PDOP2);//计算接收机坐标,返回位置的改正数rcoor.X、rcoor.Y、rcoor.Z;
			if(rcoor2.X==0&&rcoor2.Y==0&&rcoor2.Z==0)//不能循环太多，比如循环39次，这里的rcoor.X==0&&rcoor.Y==0&&rcoor.Z==0，但是是正确的
			{
				rcoor2.X = 0;
				rcoor2.Y = 0;
				rcoor2.Z = 0;
				rcoor2.P1 = 0;
				rcoor2.P2 = 0;
				break;
			}
			else
			{
				rcoor2.X = rcoor2.X + M2X0;			//新的接收机坐标=改正数+初值，下面判断，如果delt>0.001的话，返回do，将rcoor.X重新作为初值，循环计算到delt<0.001;
				rcoor2.Y = rcoor2.Y + M2Y0;
				rcoor2.Z = rcoor2.Z + M2Z0;
				//delt = rcoor2.X - M2X0;
				delt = sqrt(pow(rcoor2.X - M2X0,2.0)+pow(rcoor2.Y - M2Y0,2.0)+pow(rcoor2.Z - M2Z0,2.0));

				/*	if (fabs(delt)<0.00001)
				break;*/

			}
		}
		else if (MM2 ==0 && KK2>=4 && RR2==0)//单BDS系统，大于4时，RMS才有值;
		{
			recei_coor_single(&rcoor2,M2_bds_coor,M2_bds_wj,&KK2,M2_BDS_SR,&GDOP2,&PDOP2);//计算接收机坐标,返回位置的改正数rcoor.X、rcoor.Y、rcoor.Z;
			if(rcoor2.X==0&&rcoor2.Y==0&&rcoor2.Z==0)//不能循环太多，比如循环39次，这里的rcoor.X==0&&rcoor.Y==0&&rcoor.Z==0，但是是正确的
			{
				rcoor2.X = 0;
				rcoor2.Y = 0;
				rcoor2.Z = 0;
				rcoor2.P1 = 0;
				rcoor2.P2 = 0;
				break;
			}
			else
			{
				rcoor2.X = rcoor2.X + M2X0;			//新的接收机坐标=改正数+初值，下面判断，如果delt>0.001的话，返回do，将rcoor.X重新作为初值，循环计算到delt<0.001;
				rcoor2.Y = rcoor2.Y + M2Y0;
				rcoor2.Z = rcoor2.Z + M2Z0;
				//delt = rcoor2.X - M2X0;
				delt = sqrt(pow(rcoor2.X - M2X0,2.0)+pow(rcoor2.Y - M2Y0,2.0)+pow(rcoor2.Z - M2Z0,2.0));

				/*if (fabs(delt)<0.00001)
				break;*/

			}
		}
		else
		{
			rcoor2.X = 0;
			rcoor2.Y = 0;
			rcoor2.Z = 0;
			rcoor2.P1 = 0;
			rcoor2.P2 = 0;
			break;
		}
		//if (rcoor2.X!=0&&fabs(delt)<0.00001)
		//	break;
	}while(delt>0.00001);

	/************▼完备性▼↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*///160814河北局
	double xyz[3]={0};//改正后坐标xyz0
	double NEU[3]={0};//,horizonD000wjcf=0
	xyz[0]=rcoor2.X;xyz[1]=rcoor2.Y;xyz[2]=rcoor2.Z;
	XYZ2NEU(ih0[GridValue.Monitor_BS_ID].xyz,xyz,NEU);//NEU4差分改正后xyz0相对于真值的NEU，用于评定精度
	//horizonD000wjcf=sqrt(NEU000wjcf[0]*NEU000wjcf[0]+NEU000wjcf[1]*NEU000wjcf[1]);//改正后水平偏差
	rp rcoor_raim=rcoor2;
	int MM_raim=MM2,KK_raim=KK2,RR_raim=RR2;
	double GDOP_raim=0.0,PDOP_raim=0.0;
	double aa,bb,cc;
	aa=fabs(NEU[0]);
	bb=fabs(NEU[1]);
	cc=fabs(NEU[2]);

	int addsys=0;
	if(MM2!=0&&KK2!=0&&RR2!=0) addsys=0;
	else if(MM2!=0&&KK2!=0&&RR2==0) addsys=1;
	else if(MM2!=0&&KK2==0&&RR2==0) addsys=2;
	else if(MM2==0&&KK2!=0&&RR2==0) addsys=2;
	else return -1;

	if(rcoor2.X!=0)
	{
		if(aa>3.0||bb>3.0/*||cc>4.0*/)//N,E,U限差224m，经过半天采集应设为112m，NEU调整160413，河北测试33,160812
		{
			int B_bad_num = 0, G_bad_num = 0, R_bad_num = 0;				//BDS、GPS残差超限的个数;
			int T = MM_raim + KK_raim+ RR_raim;						//多系统定位总的卫星个数Totle;
			int COL = 6;
			int i, j;									    //为了进行循环;
			int final_N, final_P, final_R;
			double X_raim0, Y_raim0, Z_raim0;
			X_raim0 = rcoor_raim.X;
			Y_raim0 = rcoor_raim.Y;
			Z_raim0 = rcoor_raim.Z;

			double xyztch[3]={0};//剔除后坐标xyz0
			double NEUtch[3]={0};//
			//int index;//是否循环计算的标志,也即是是否有粗差的标志;
			double a=0,b=0,c=0;
			do
			{
				if(chaoxian_num>10)
				{
					/*memset(Bn,0x00,sizeof(int)*200);
					memset(Bp,0x00,sizeof(int)*200);*/
					//memset(VBPC,0x00,sizeof(VBS_PR_CR)*30);	//该历元放弃20150729,VBS_PR_CR)*200很重要20150805;
					VBPC[IWGD].G_num=0;
					VBPC[IWGD].C_num=0;
					VBPC[IWGD].R_num=0;
					break;
				}
				//index = 0;
				double	*ll = new	double[T]();		//课本P57参数  等加以double	(*ll)[1]=	 new	double[T][1];
				double	*mm = new	double[T]();
				double	*nn = new	double[T]();
				double	*L = new	double[T]();
				double	*A = new	double[T * COL]();		//状态矩阵A;
				double	*AT = new	double[COL * T]();		//状态矩阵A的转置;
				double	*P = new	double[T*T]();		//权矩阵P;              ()是对动态内存进行初始化
				double	*ATP = new	double[COL * T]();		//A的转置乘以P;
				double	*ATPA = new	double[COL * COL]();		//A的转置乘以P乘以A;
				double	*inv_ATPA = new	double[COL * COL]();		//(A的转置乘以P乘以A)的逆;
				double	*ATPL = new	double[COL]();		//A的转置乘以P乘以L;
				double	*result = new	double[COL]();		//(A的转置乘以P乘以A)乘以(A的转置乘以P乘以L)，(inv_ATPA)(ATPL);


				double	*AX = new	double[T]();		//A乘以X;
				double  *V = new	double[T]();		//V=AX-L
				double	*VT = new	double[1 * T]();
				double	*VTP = new	double[1 * T]();
				double	*VTPV = new	double[T * 1]();

				///////////////////////////////////////////列法方程;

				//cout<<"系数矩阵B和L"<<endl;																	//
				for (i = 0; i<MM_raim; i++)
				{
					ll[i] = (M2_gps_coor.X[i] - rcoor_raim.X) / M2_GPS_SR[i];
					mm[i] = (M2_gps_coor.Y[i] - rcoor_raim.Y) / M2_GPS_SR[i];
					nn[i] = (M2_gps_coor.Z[i] - rcoor_raim.Z) / M2_GPS_SR[i];
					A[i * (COL-addsys) + 0] = ll[i];
					A[i * (COL-addsys) + 1] = mm[i];
					A[i * (COL-addsys) + 2] = nn[i];
					A[i * (COL-addsys) + 3] = -1;
					//A[i*COL+4]=0;								//初始化了就不需要了
					L[i] = M2_GPS_SR[i] - M2_gps_wj[i];

					//printf("%8.3f%8.3f%8.3f%8.3f%8.3f%16.3f\n",A[i*5+0],A[i*5+1],A[i*5+2],A[i*5+3],A[i*5+4],L[i]);	//

					P[i*T + i] = 1;									//给GPS定的权
				}
				for (j = MM_raim; j<T; j++)
				{
					ll[j] = (M2_bds_coor.X[j - MM_raim] - rcoor_raim.X) / M2_BDS_SR[j - MM_raim];
					mm[j] = (M2_bds_coor.Y[j - MM_raim] - rcoor_raim.Y) / M2_BDS_SR[j - MM_raim];
					nn[j] = (M2_bds_coor.Z[j - MM_raim] - rcoor_raim.Z) / M2_BDS_SR[j - MM_raim];
					A[j * (COL-addsys) + 0] = ll[j];
					A[j * (COL-addsys) + 1] = mm[j];
					A[j * (COL-addsys) + 2] = nn[j];
					//A[j*COL+3]=0;								//初始化了就不需要了;
					A[j * (COL-addsys) + 4] = -1;
					L[j] = M2_BDS_SR[j - MM_raim] - M2_bds_wj[j - MM_raim];

					//printf("%8.3f%8.3f%8.3f%8.3f%8.3f%16.3f\n",A[j*5+0],A[j*5+1],A[j*5+2],A[j*5+3],A[j*5+4],L[j]);	//

					P[j*T + j] = 1;									//给BDS定的权
				}
				int nGPSBDS_raim = MM_raim+KK_raim;
				for (int j1 = nGPSBDS_raim; j1<T; j1++)//GLONASS
				{
					ll[j1] = (M2_glo_coor.X[j1 - nGPSBDS_raim] - rcoor_raim.X) / M2_GLO_SR[j1 - nGPSBDS_raim];
					mm[j1] = (M2_glo_coor.Y[j1 - nGPSBDS_raim] - rcoor_raim.Y) / M2_GLO_SR[j1 - nGPSBDS_raim];
					nn[j1] = (M2_glo_coor.Z[j1 - nGPSBDS_raim] - rcoor_raim.Z) / M2_GLO_SR[j1 - nGPSBDS_raim];
					A[j1 * (COL-addsys) + 0] = ll[j1];
					A[j1 * (COL-addsys) + 1] = mm[j1];
					A[j1 * (COL-addsys) + 2] = nn[j1];
					//A[j*COL+3]=0;								//初始化了就不需要了;
					A[j1 * (COL-addsys) + 5] = -1;
					L[j1] = M2_GLO_SR[j1 - nGPSBDS_raim] - M2_glo_wj[j1 - nGPSBDS_raim];

					//printf("%8.3f%8.3f%8.3f%8.3f%8.3f%16.3f\n",A[j*5+0],A[j*5+1],A[j*5+2],A[j*5+3],A[j*5+4],L[j]);	//

					P[j1*T + j1] = 1;									//给GLO定的权
				}

				///////////////////////////////////////////通过函数的指针进行矩阵的运算，传出需要的矩阵;
				M_Tra(T, (COL-addsys), A, AT);							//矩阵转置	A的转置		传出AT;
				M_Mul((COL-addsys), T, T, AT, P, ATP);						//矩阵相乘	AT乘P		传出ATP;
				M_Mul((COL-addsys), T, (COL-addsys), ATP, A, ATPA);					//			ATP乘A		传出ATPA;
				M_Inv((COL-addsys), ATPA, inv_ATPA);						//矩阵求逆	ATPA的逆		传出inv_ATPA;
				M_Mul((COL-addsys), T, 1, ATP, L, ATPL);					//			ATP乘L		传出ATPL;
				M_Mul((COL-addsys), (COL-addsys), 1, inv_ATPA, ATPL, result);			//			inv_ATPA乘ATPL传出result;

				//cout<<inv_ATPA[1]<<inv_ATPA[2]<<inv_ATPA[3]<<inv_ATPA[4]<<inv_ATPA[5]<<endl;
				//cout<<ATPL[1]<<ATPL[2]<<ATPL[3]<<ATPL[4]<<ATPL[5]<<endl;
				if (inv_ATPA != NULL)
				{
					rcoor_raim.X = result[0];
					rcoor_raim.Y = result[1];
					rcoor_raim.Z = result[2];
					rcoor_raim.P1 = result[3];
					rcoor_raim.P2 = result[4];
					rcoor_raim.P3 = result[5];

					for (i = 0; i<(COL-addsys); i++)
						GDOP_raim += inv_ATPA[i * (COL-addsys) + i];
					sate_num[IWGD].GDOP_raim = sqrt(GDOP_raim);
					for (i = 0; i<3; i++)
						PDOP_raim += inv_ATPA[i * (COL-addsys) + i];
					sate_num[IWGD].PDOP_raim = sqrt(PDOP_raim);
				}
				else
				{
					rcoor_raim.X = 0;
					rcoor_raim.Y = 0;
					rcoor_raim.Z = 0;
					rcoor_raim.P1 = 0;
					rcoor_raim.P2 = 0;
					rcoor_raim.P3 = 0;
					//printf("这个历元数据无法求解!\n");
					//system("pause");
				}

				double X[6][1];
				X[0][0] = rcoor_raim.X;
				X[0][1] = rcoor_raim.Y;
				X[0][2] = rcoor_raim.Z;
				X[0][3] = rcoor_raim.P1;
				X[0][4] = rcoor_raim.P2;
				X[0][5] = rcoor_raim.P3;
				//double	*AX=	new	double[T]();			//A乘以X;
				M_Mul(T, (COL-addsys), 1, A, X[0], AX);							//矩阵相乘;
				//double  *V=		new	double[T]();			//V=AX-L

				for (int p = 0; p<T; p++)
				{
					V[p] = AX[p] - L[p];
				}
				//double *VT=		new	double[1*T]();
				//double *VTP=	new	double[1*T]();
				//double *VTPV=	new	double[T*1]();

				M_Tra(T, 1, V, VT);								//矩阵转置	A的转置		传出AT;
				M_Mul(1, T, T, VT, P, VTP);							//矩阵相乘	AT乘P		传出ATP;
				M_Mul(1, T, 1, VTP, V, VTPV);
				double RMS_raim = sqrt(*VTPV / (T - (COL-addsys)));
				double w[32]={0.0};
				for (i = 0; i<T; i++)
				{
					w[i] = fabs(V[i]) / (RMS_raim*sqrt((T - 1.0) / T));
					//printf("%16.8f\n",w[i]);				//
				}
				double w1=0.0;int n_s=0;
				for(i=0;i<T;i++)
				{
					if(w[i]> w1)
					{
						w1=w[i];
						n_s=i;
					}
				}

				int NNN,PPP,RRR;
				NNN = MM_raim;
				PPP = KK_raim;
				RRR = RR_raim;

				if (n_s>NNN+PPP - 1)			//说明是GLO卫星的 160814
				{
					bad_RPRN[chaoxian_num] = M2_RPRN[n_s - NNN-PPP];//如果GPS7颗，BDS9颗，现在pp=8，也就是w中第9个，那么就是BDS卫星的第2个对应于1，即8-7=1;
					//chaoxian_num++;
					//for(int j=1;j<5;j++)//四个基准站，依次消除坏星;
					//{
					for (int m=0;m<VBPC[IWGD].R_num;m++)//从0开始依次比对prn
					{
						if (bad_RPRN[chaoxian_num]==VBPC[IWGD].R_PRN[m])//当prn相同时就消除这颗卫星对应的内容;
						{
							for (int s = m; s<VBPC[IWGD].R_num; s++)//从坏星开始将后一个星内容覆盖前一个卫星内容;
							{
								VBPC[IWGD].R_PRN[s]=VBPC[IWGD].R_PRN[s+1];
								VBPC[IWGD].RPC[s]=VBPC[IWGD].RPC[s+1];
							}
							VBPC[IWGD].R_num--;
							break;
						}
					}
					//}
					R_bad_num++;
					RR_raim = RRR - 1;		//新的GLO卫星个数
					chaoxian_num++;
				}
				else if (n_s>NNN-1&&n_s<=NNN+PPP-1)			//说明是BDS卫星的
				{
					bad_BPRN[chaoxian_num] = M2_BPRN[n_s - NNN];//如果GPS7颗，BDS9颗，现在pp=8，也就是w中第9个，那么就是BDS卫星的第2个对应于1，即8-7=1;
					for (int m=0;m<VBPC[IWGD].C_num;m++)//从0开始依次比对prn,IWGD的VBPC,注意20150807!!!!!;
					{
						if (bad_BPRN[chaoxian_num]==VBPC[IWGD].C_PRN[m])//当prn相同时就消除这颗卫星对应的内容;
						{
							for (int s1 = m; s1<VBPC[IWGD].C_num; s1++)//从坏星开始将后一个星内容覆盖前一个卫星内容;
							{
								VBPC[IWGD].C_PRN[s1]=VBPC[IWGD].C_PRN[s1+1];
								VBPC[IWGD].CPC[s1]=VBPC[IWGD].CPC[s1+1];
							}
							VBPC[IWGD].C_num--;
							break;
						}
					}

					B_bad_num++;
					KK_raim = PPP - 1;		//新的BDS卫星个数
					chaoxian_num++;
				}
				else					//说明是GPS卫星的
				{
					bad_GPRN[chaoxian_num] = M2_GPRN[n_s];
					for (int m=0;m<VBPC[IWGD].G_num;m++)//从0开始依次比对prn,IWGD的VBPC,注意20150807!!!!!;
					{
						if (bad_GPRN[chaoxian_num]==VBPC[IWGD].G_PRN[m])//当prn相同时就消除这颗卫星对应的内容;
						{
							for (int s = m; s<VBPC[IWGD].G_num; s++)//从坏星开始将后一个星内容覆盖前一个卫星内容;
							{
								VBPC[IWGD].G_PRN[s]=VBPC[IWGD].G_PRN[s+1];
								VBPC[IWGD].GPC[s]=VBPC[IWGD].GPC[s+1];
							}
							VBPC[IWGD].G_num--;
							break;
						}
					}
					G_bad_num++;
					MM_raim = NNN - 1;		//新的GPS卫星个数
					chaoxian_num++;
				}

				KK2=KK_raim;MM2=MM_raim;RR2=RR_raim;

				NWDGNSS_3SYS_MOVING_POS_MODULE(GridValue, ih0[GridValue.Monitor_BS_ID].xyz,VBPC, dg[1],geph,rcoor2,sate_num[IWGD]);
				if(rcoor2.X!=0)
				{
					xyztch[0]=rcoor2.X;xyztch[1]=rcoor2.Y;xyztch[2]=rcoor2.Z;
					XYZ2NEU(ih0[GridValue.Monitor_BS_ID].xyz,xyztch,NEUtch);//NEU4差分改正后xyz0相对于真值的NEU，用于评定精度
				}
				else
				{
					NEUtch[0]=0;
					NEUtch[1]=0;
					NEUtch[2]=0;
					/*memset(Bn,0x00,sizeof(int)*20);
					memset(Bp,0x00,sizeof(int)*20);*/
					//memset(VBPC,0x00,sizeof(VBS_PR_CR)*30);//VBS_PR_CR)*200很重要20150805;
					VBPC[IWGD].G_num=0;
					VBPC[IWGD].C_num=0;
					VBPC[IWGD].R_num=0;
					break;
				}

				a=fabs(NEUtch[0]);
				b=fabs(NEUtch[1]);
				c=fabs(NEUtch[2]);

				delete  []ll;
				delete	[]mm;
				delete	[]nn;
				delete	[]L;
				delete	[]A;
				delete	[]AT;
				delete	[]P;	
				delete	[]ATP;
				delete	[]ATPA;
				delete	[]inv_ATPA;
				delete	[]ATPL;
				delete	[]result;
				delete	[]AX;
				delete  []V;	
				delete	[]VT;
				delete	[]VTP;
				delete	[]VTPV;

			}while(a>3.0||b>3.0/*||c>4.0*/);//N,E,U限差224m，经过半天采集应设为112m
		}
	}
}
void CNDGNSS::NWDGNSS_3SYS_MOVING_POS_MODULE(GridAttribute GridValue,double  M_coor[],VBS_PR_CR VBPC[], DATG dg0, GEPH geph[], rp &rcoor2,Sate_NUM &sate_num)
{
	double	delt = 1;								//do...while()限制条件中的接收机X坐标迭代控制条件
	double	GDOP2 = 0, PDOP2 = 0;
	DATG dg[5] = { 0 };
	//int i = 0;
	dg[1] = dg0;
	BS_PR_CR BPC={0};
	//这里因为是车载，所以流动站一直在变，那么如果流动站有坐标，就用流动站坐标到各基准站的距离，如果流动站坐标为0，就用监测站坐标，一般流动站第一次坐标为0，以后都会有值，为上一次的解得的值;
	IOFH ih3[4] = { 0 };

	int pp=0;
	int nn1=0;
	int rr=0;
	int IWGD=GridValue.Grid_ID;
	if(IWGD!=99999)
	{
		for(int n1 = 0 ;n1 < VBPC[IWGD].G_num; n1++)
		{
			BPC.G_PRN[n1] = VBPC[IWGD].G_PRN[n1];
			BPC.GPC[n1] = VBPC[IWGD].GPC[n1];
		}

		for(int p1 = 0 ;p1 < VBPC[IWGD].C_num; p1++)
		{
			BPC.C_PRN[p1] = VBPC[IWGD].C_PRN[p1];
			BPC.CPC[p1] = VBPC[IWGD].CPC[p1];
		}
		for(int r1 = 0 ;r1 < VBPC[IWGD].R_num; r1++)
		{
			BPC.R_PRN[r1] = VBPC[IWGD].R_PRN[r1];
			BPC.RPC[r1] = VBPC[IWGD].RPC[r1];
		}
		pp=VBPC[IWGD].C_num;
		nn1=VBPC[IWGD].G_num;
		rr=VBPC[IWGD].R_num;
	}


	/************▼流动站▼↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/

	double	M2X0, M2Y0, M2Z0;							//流动站初始坐标;
	double	M2g_swj, M2g_R, M2b_swj, M2b_R,M2r_swj, M2r_R;
	double	M2G_XK, M2G_YK, M2G_ZK, M2B_XK, M2B_YK, M2B_ZK, M2R_XK, M2R_YK, M2R_ZK;	//初始坐标;
	int		MM2, KK2, RR2,ALL_GB2;
	//rp		rcoor2={0};
	rcoor2.X = M_coor[0];
	rcoor2.Y = M_coor[1];
	rcoor2.Z = M_coor[2];


	int xunhuan=0;
	do		//最多循环10次跳出，代替do。。。。while;
	{ 


		if( xunhuan>14)	{break;}		//最多循环10次跳出，代替do。。。。while;
		xunhuan++;

		double	M2gps_wj[40] = { 0 }, M2GPS_SR[40] = { 0 };	//流动站解算的gps伪距&近似距离——存储值;
		double	M2bds_wj[40] = { 0 }, M2BDS_SR[40] = { 0 };	//流动站解算的bds伪距&近似距离——存储值;
		double	M2glo_wj[40] = { 0 }, M2GLO_SR[40] = { 0 };	//流动站解算的glo伪距&近似距离——存储值;
		int		M2GPRN[40] = { 0 };						//流动站gpsPRN号——存储值;
		int		M2BPRN[40] = { 0 };						//流动站bdsPRN号——存储值;
		int		M2RPRN[40] = { 0 };						//流动站gloPRN号——存储值;
		sp		M2gps_coor = { 0 }, M2bds_coor = { 0 }, M2glo_coor = { 0 };		//流动站解算的gps与bds的卫星坐标——存储值;

		double	M2_gps_wj[40] = { 0 }, M2_GPS_SR[40] = { 0 };//流动站最终解算;
		double	M2_bds_wj[40] = { 0 }, M2_BDS_SR[40] = { 0 };//流动站最终解算;
		double	M2_glo_wj[40] = { 0 }, M2_GLO_SR[40] = { 0 };//流动站最终解算;
		int		M2_GPRN[40] = { 0 };					//流动站最终解算;
		int		M2_BPRN[40] = { 0 };					//流动站最终解算;
		int		M2_RPRN[40] = { 0 };					//流动站最终解算;
		sp		M2_gps_coor = { 0 }, M2_bds_coor = { 0 }, M2_glo_coor = { 0 };	//流动站最终解算;


		double check2_gps[40] = { 0 }, check2_bds[40] = { 0 }, check2_glo[40] = { 0 };//检测伪距改正输出;
		int	m2 = 0, k2 = 0, r2 = 0;								//循环回代置零;
		M2X0 = rcoor2.X;								//用于循环回代;
		M2Y0 = rcoor2.Y;
		M2Z0 = rcoor2.Z;

		for (int ii = 0; ii<dg[1].nsat; ii++)				//基于流动站计算卫星位置及伪距&卫地距;
		{
			if(dg[1].prn[ii] >= 1 &&dg[1].prn[ii] < 33)
			{
				M2g_swj = 0, M2g_R = 0;
				M2G_XK = 0, M2G_YK = 0, M2G_ZK = 0;
				int prn_satellite = dg[1].prn[ii];
				if (geph[prn_satellite].a[24] == 1)//卫星不健康
					continue;

				double svclk=GetSVpos(dg[1].tg.week,dg[1].tg.second,geph[prn_satellite].a,M2X0, M2Y0, M2Z0,&M2G_XK, &M2G_YK, &M2G_ZK); 
				if(svclk > 10.0)
					continue;
				M2g_R=sqrt(pow(M2G_XK-M2X0,2)+pow(M2G_YK-M2Y0,2)+pow(M2G_ZK-M2Z0,2));//卫地距
				double rs[3]={0.0},rr[3]={0.0},r2suv[3]={0},pos[3]={0},azel[2]={0};
				double EL = 0;
				rs[0]=M2G_XK;
				rs[1]=M2G_YK;
				rs[2]=M2G_ZK;
				rr[0]=M2X0;
				rr[1]=M2Y0;
				rr[2]=M2Z0;
				geodist(rs,rr,r2suv);
				ecef2pos(rr,pos);
				EL=satazel(pos,r2suv,azel);
				if(fabs(EL*R2D)>15.0)//判断卫星高度角
				{
					M2g_swj = dg[1].data[ii][0] + svclk*299792458.0 ;//伪距
				}
				else							//高度角为10度((PI/18=0.17453292519943))，小于10的卫星舍去  15度 PI/12=0.2617993877991
				{
					M2g_R = 0;
					M2g_swj = 0;
					M2G_XK = 0;
					M2G_YK = 0;
					M2G_ZK = 0;
				}
				if (M2g_swj != 0 && M2g_R != 0)
				{
					M2gps_wj[m2] = M2g_swj;
					M2GPS_SR[m2] = M2g_R;
					M2GPRN[m2] = dg[1].prn[ii];
					M2gps_coor.X[m2] = M2G_XK;
					M2gps_coor.Y[m2] = M2G_YK;
					M2gps_coor.Z[m2] = M2G_ZK;

					check2_gps[m2] = M2g_R - M2g_swj;					//检测改正值正确与否,与BDS的改正值对比,注意：检测时要加入卫星钟差，以使对比与BDS的改正值是否一致,正确的应该和BDS是一致的;
					m2++;											//m为可利用GPS卫星数目
				}
			}
			//if(dg[1].prn[ii] >= 1 &&dg[1].prn[ii] < 33)
			//{
			//	M2g_swj = 0, M2g_R = 0;
			//	M2G_XK = 0, M2G_YK = 0, M2G_ZK = 0;
			//	GNSS_POS_MODULE(geph, dg, 1, M2X0, M2Y0, M2Z0, &M2g_swj, &M2g_R, &M2G_XK, &M2G_YK, &M2G_ZK, ii, 1);//dg后面的参数为站号,为了配合dg【】中的号;
			//	if (M2g_swj != 0 && M2g_R != 0)
			//	{
			//		M2gps_wj[m2] = M2g_swj;
			//		M2GPS_SR[m2] = M2g_R;
			//		M2GPRN[m2] = dg[1].prn[ii];
			//		M2gps_coor.X[m2] = M2G_XK;
			//		M2gps_coor.Y[m2] = M2G_YK;
			//		M2gps_coor.Z[m2] = M2G_ZK;

			//		check2_gps[m2] = M2g_R - M2g_swj;					//检测改正值正确与否,与BDS的改正值对比,注意：检测时要加入卫星钟差，以使对比与BDS的改正值是否一致,正确的应该和BDS是一致的;
			//		m2++;											//m为可利用GPS卫星数目
			//	}
			//}
			if(dg[1].prn[ii] >= 33 && dg[1].prn[ii] < 57)//glonass 160814河北
			{
				M2r_swj = 0, M2r_R = 0;
				M2R_XK = 0, M2R_YK = 0, M2R_ZK = 0;
				int prn_satellite = dg[1].prn[ii];
				if (geph[prn_satellite].a[8] == 1)//卫星不健康
					continue;
				if (geph[prn_satellite].a[5] == 0.0||geph[prn_satellite].a[9] == 0.0||geph[prn_satellite].a[13] == 0.0)
					continue;

				double  tc=0,tc1=0;
				gtime_t glo_t;
				glo_t.time=geph[prn_satellite].a[0];
				glo_t.sec =geph[prn_satellite].a[1];
				gtime_t glo_ot = gpst2time(dg[1].tg.week, dg[1].tg.second);
				double svclk=GetSVpos_GLO(glo_t,glo_ot,dg[1].data[ii][0],geph[prn_satellite].a,M2X0,M2Y0,M2Z0,&M2R_XK, &M2R_YK, &M2R_ZK,tc);

				if(svclk > 10.0)
					continue;

				M2r_R=sqrt(pow(M2R_XK-M2X0,2)+pow(M2R_YK-M2Y0,2)+pow(M2R_ZK-M2Z0,2));//卫地距

				double rs[3]={0.0},rr[3]={0.0},r2suv[3]={0},pos[3]={0},azel[2]={0};
				double EL = 0;
				rs[0]=M2R_XK;
				rs[1]=M2R_YK;
				rs[2]=M2R_ZK;
				rr[0]=M2X0;
				rr[1]=M2Y0;
				rr[2]=M2Z0;
				geodist(rs,rr,r2suv);
				ecef2pos(rr,pos);
				EL=satazel(pos,r2suv,azel);
				if(fabs(EL*R2D)>15.0)//判断卫星高度角
				{
					M2r_swj = dg[1].data[ii][0] + svclk*299792458.0 ;//伪距
				}
				else							//高度角为10度((PI/18=0.17453292519943))，小于10的卫星舍去  15度 PI/12=0.2617993877991
				{
					M2r_R = 0;
					M2r_swj = 0;
					M2R_XK = 0;
					M2R_YK = 0;
					M2R_ZK = 0;
				}
				if (M2r_swj != 0 && M2r_R != 0)
				{
					M2glo_wj[r2] = M2r_swj;
					M2GLO_SR[r2] = M2r_R;
					M2RPRN[r2] = dg[1].prn[ii];
					M2glo_coor.X[r2] = M2R_XK;
					M2glo_coor.Y[r2] = M2R_YK;
					M2glo_coor.Z[r2] = M2R_ZK;

					check2_glo[r2] = M2r_R - M2r_swj;					//检测改正值正确与否,与GLO的改正值对比,注意：检测时要加入卫星钟差，以使对比与BDS的改正值是否一致,正确的应该和BDS是一致的;
					r2++;	
				}
			}
			//if(dg[1].prn[ii] >= 33 && dg[1].prn[ii] < 57)//glonass  //160814河北
			//{
			//	M2r_swj = 0, M2r_R = 0;
			//	double rs[6];
			//	memset(rs,0x00,sizeof(rs));
			//	GLONASS_POS_MODULE(geph,dg,1,M2X0,M2Y0,M2Z0,&M2r_swj,&M2r_R,rs,ii);//glonass
			//	if (M2r_swj != 0 && M2r_R != 0)
			//	{
			//		M2glo_wj[r2] = M2r_swj;
			//		M2GLO_SR[r2] = M2r_R;
			//		M2RPRN[r2] = dg[1].prn[ii];
			//		M2glo_coor.X[r2] = rs[0];
			//		M2glo_coor.Y[r2] = rs[1];
			//		M2glo_coor.Z[r2] = rs[2];

			//		check2_glo[r2] = M2r_R - M2r_swj;					//检测改正值正确与否,与BDS的改正值对比,注意：检测时要加入卫星钟差，以使对比与BDS的改正值是否一致,正确的应该和BDS是一致的;
			//		r2++;	
			//	}
			//}
			if(dg[1].prn[ii] >= 161 && dg[1].prn[ii] < 181)
			{
				M2b_swj = 0, M2b_R = 0;
				M2B_XK = 0, M2B_YK = 0, M2B_ZK = 0;
				int prn_satellite = dg[1].prn[ii];
				if (geph[prn_satellite].a[24] == 1)//卫星不健康
					continue;
				double svclk=0.0;
				if(prn_satellite>165)
				{
					svclk=GetSVpos_BDS(dg[1].tg.week,dg[1].tg.second-14,geph[prn_satellite].a,M2X0,M2Y0,M2Z0,&M2B_XK,&M2B_YK, &M2B_ZK); 
					if(svclk > 10.0)
						continue;
				}
				else if(prn_satellite<=165)
				{
					svclk=GetSVpos_GEO(dg[1].tg.week,dg[1].tg.second-14,geph[prn_satellite].a,M2X0,M2Y0,M2Z0,&M2B_XK,&M2B_YK, &M2B_ZK);
					if(svclk > 10.0)
						continue;
				}

				M2b_R=sqrt(pow(M2B_XK-M2X0,2)+pow(M2B_YK-M2Y0,2)+pow(M2B_ZK-M2Z0,2));//卫地距

				double rs[3]={0.0},rr[3]={0.0},r2suv[3]={0},pos[3]={0},azel[2]={0};
				double EL = 0;
				rs[0]=M2B_XK;
				rs[1]=M2B_YK;
				rs[2]=M2B_ZK;
				rr[0]=M2X0;
				rr[1]=M2Y0;
				rr[2]=M2Z0;
				geodist(rs,rr,r2suv);
				ecef2pos(rr,pos);
				EL=satazel(pos,r2suv,azel);
				if(fabs(EL*R2D)>15.0)//判断卫星高度角
				{
					M2b_swj = dg[1].data[ii][0] + svclk*299792458.0 ;//伪距
				}
				else							//高度角为10度((PI/18=0.17453292519943))，小于10的卫星舍去  15度 PI/12=0.2617993877991
				{
					M2b_R = 0;
					M2b_swj = 0;
					M2B_XK = 0;
					M2B_YK = 0;
					M2B_ZK = 0;
				}
				if (M2b_swj != 0 && M2b_R != 0)
				{
					M2bds_wj[k2] = M2b_swj;
					M2BDS_SR[k2] = M2b_R;
					M2BPRN[k2] = dg[1].prn[ii];
					M2bds_coor.X[k2] = M2B_XK;
					M2bds_coor.Y[k2] = M2B_YK;
					M2bds_coor.Z[k2] = M2B_ZK;

					check2_bds[k2] = M2b_R - M2b_swj;			//检测改正值正确与否,与GPS的改正值对比,注意：检测时要加入卫星钟差，以使对比与GPS的改正值是否一致,正确的应该和GPS是一致的;
					k2++;								//m为可利用GPS卫星数目
				}
			}
			//if(dg[1].prn[ii] >= 161 && dg[1].prn[ii] < 181)
			//{
			//	M2b_swj = 0, M2b_R = 0;
			//	M2B_XK = 0, M2B_YK = 0, M2B_ZK = 0;
			//	GNSS_POS_MODULE(geph, dg, 1, M2X0, M2Y0, M2Z0, &M2b_swj, &M2b_R, &M2B_XK, &M2B_YK, &M2B_ZK, ii, 2);//dg后面的参数为站号,为了配合dg【】中的号;
			//	if (M2b_swj != 0 && M2b_R != 0)
			//	{
			//		M2bds_wj[k2] = M2b_swj;
			//		M2BDS_SR[k2] = M2b_R;
			//		M2BPRN[k2] = dg[1].prn[ii];
			//		M2bds_coor.X[k2] = M2B_XK;
			//		M2bds_coor.Y[k2] = M2B_YK;
			//		M2bds_coor.Z[k2] = M2B_ZK;

			//		check2_bds[k2] = M2b_R - M2b_swj;			//检测改正值正确与否,与GPS的改正值对比,注意：检测时要加入卫星钟差，以使对比与GPS的改正值是否一致,正确的应该和GPS是一致的;
			//		k2++;								//m为可利用GPS卫星数目
			//	}
			//}
		}

		/************▼匹配历元改正数▼↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
		int mm2 = 0, kk2 = 0, rr2 = 0;							//该历元中流动站和改正数相匹配的数;
		for (int ii = 0; ii<m2; ii++)				//匹配从n个基准站传过来的通过反距离加权后的GPS伪距改正值;
		{
			for (int jj = 0; jj<nn1; jj++)
			{
				//if (M2GPRN[ii]==BPC.G_PRN[jj]&&BPC.C_PRN[jj]!=bad_BPRN[0]&&BPC.C_PRN[jj]!=bad_BPRN[1]&&BPC.C_PRN[jj]!=bad_BPRN[2]&&BPC.C_PRN[jj]!=bad_BPRN[3]&&BPC.C_PRN[jj]!=bad_BPRN[4])
				if (M2GPRN[ii] == BPC.G_PRN[jj])
				{
					M2_gps_wj[mm2] = M2gps_wj[ii] + BPC.GPC[jj];
					M2_GPS_SR[mm2] = M2GPS_SR[ii];
					M2_GPRN[mm2] = M2GPRN[ii];
					M2_gps_coor.X[mm2] = M2gps_coor.X[ii];
					M2_gps_coor.Y[mm2] = M2gps_coor.Y[ii];
					M2_gps_coor.Z[mm2] = M2gps_coor.Z[ii];
					mm2++;
					break;
				}
			}
		}
		for (int ii = 0; ii<k2; ii++)				//匹配从n个基准站传过来的的通过反距离加权后的BDS伪距改正值;
		{
			for (int jj = 0; jj<pp; jj++)
			{
				//if (M2BPRN[ii]==BPC.C_PRN[jj]&&BPC.C_PRN[jj]!=bad_BPRN[0]&&BPC.C_PRN[jj]!=bad_BPRN[1]&&BPC.C_PRN[jj]!=bad_BPRN[2]&&BPC.C_PRN[jj]!=bad_BPRN[3]&&BPC.C_PRN[jj]!=bad_BPRN[4])
				if (M2BPRN[ii] == BPC.C_PRN[jj])
				{
					M2_bds_wj[kk2] = M2bds_wj[ii] + BPC.CPC[jj];
					M2_BDS_SR[kk2] = M2BDS_SR[ii];
					M2_BPRN[kk2] = M2BPRN[ii];
					M2_bds_coor.X[kk2] = M2bds_coor.X[ii];
					M2_bds_coor.Y[kk2] = M2bds_coor.Y[ii];
					M2_bds_coor.Z[kk2] = M2bds_coor.Z[ii];
					kk2++;
					break;
				}
			}
		}
		for (int ii = 0; ii<r2; ii++)				//匹配从n个基准站传过来的的通过反距离加权后的GLO伪距改正值;160814
		{
			for (int jj = 0; jj<rr; jj++)
			{
				if (M2RPRN[ii] == BPC.R_PRN[jj])
				{
					M2_glo_wj[rr2] = M2glo_wj[ii] + BPC.RPC[jj];
					M2_GLO_SR[rr2] = M2GLO_SR[ii];
					M2_RPRN[rr2] = M2RPRN[ii];
					M2_glo_coor.X[rr2] = M2glo_coor.X[ii];
					M2_glo_coor.Y[rr2] = M2glo_coor.Y[ii];
					M2_glo_coor.Z[rr2] = M2glo_coor.Z[ii];
					rr2++;
					break;
				}
			}
		}

		/************▼定位解算▼↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
		MM2 = mm2, KK2 = kk2, RR2 = rr2;
		ALL_GB2 = MM2 + KK2 + RR2;
		if (ALL_GB2 > 6 && MM2>0 && KK2>0 && RR2>0)//gps/bds/glonass三系统160814
			{
				gps_bds_glo_coor(&rcoor2,M2_gps_coor, M2_gps_wj, M2_GPS_SR, M2_bds_coor, M2_bds_wj, M2_BDS_SR,M2_glo_coor,M2_glo_wj,M2_GLO_SR,ALL_GB2, MM2, KK2, RR2, &GDOP2, &PDOP2, dg[1].tg.second);

				if (rcoor2.X != 0 && rcoor2.Y != 0 && rcoor2.Z != 0)
				{
					rcoor2.X = rcoor2.X + M2X0;			//新的接收机坐标=改正数+初值，下面判断，如果delt>0.001的话，返回do，将rcoor.X重新作为初值，循环计算到delt<0.001;
					rcoor2.Y = rcoor2.Y + M2Y0;
					rcoor2.Z = rcoor2.Z + M2Z0;
					//delt = rcoor2.X - M2X0;
					delt = sqrt(pow(rcoor2.X - M2X0,2.0)+pow(rcoor2.Y - M2Y0,2.0)+pow(rcoor2.Z - M2Z0,2.0));

					/*if (fabs(delt)<0.00001)
					break;*/
				}
				else
				{
					rcoor2.X = 0;
					rcoor2.Y = 0;
					rcoor2.Z = 0;
					rcoor2.P1 = 0;
					rcoor2.P2 = 0;
					rcoor2.P3 = 0;
					break;
				}
			}
		else if (ALL_GB2 > 5 && MM2>0 && KK2>0 && RR2==0)//GPS/BDS双系统;160814
		{
			recei_coor(&rcoor2, M2_gps_coor, M2_gps_wj, M2_GPS_SR, M2_bds_coor, M2_bds_wj, M2_BDS_SR, ALL_GB2, MM2, KK2, &GDOP2, &PDOP2, dg[1].tg.second);//计算接收机坐标,返回位置的改正数rcoor.X、rcoor.Y、rcoor.Z;
			if (rcoor2.X != 0 && rcoor2.Y != 0 && rcoor2.Z != 0)
			{
				rcoor2.X = rcoor2.X + M2X0;			//新的接收机坐标=改正数+初值，下面判断，如果delt>0.001的话，返回do，将rcoor.X重新作为初值，循环计算到delt<0.001;
				rcoor2.Y = rcoor2.Y + M2Y0;
				rcoor2.Z = rcoor2.Z + M2Z0;
				//delt = rcoor2.X - M2X0;
				delt = sqrt(pow(rcoor2.X - M2X0,2.0)+pow(rcoor2.Y - M2Y0,2.0)+pow(rcoor2.Z - M2Z0,2.0));

				/*if (fabs(delt)<0.00001)
				break;*/
			}
			else
			{
				rcoor2.X = 0;
				rcoor2.Y = 0;
				rcoor2.Z = 0;
				rcoor2.P1 = 0;
				rcoor2.P2 = 0;
				break;
			}
		}
		else if (MM2 >= 4 && KK2==0)//单GPS系统，大于4时，RMS才有值;
		{
			recei_coor_single(&rcoor2,M2_gps_coor,M2_gps_wj,&MM2,M2_GPS_SR,&GDOP2,&PDOP2);//计算接收机坐标,返回位置的改正数rcoor.X、rcoor.Y、rcoor.Z;
			if(rcoor2.X==0&&rcoor2.Y==0&&rcoor2.Z==0)//不能循环太多，比如循环39次，这里的rcoor.X==0&&rcoor.Y==0&&rcoor.Z==0，但是是正确的
			{
				rcoor2.X = 0;
				rcoor2.Y = 0;
				rcoor2.Z = 0;
				rcoor2.P1 = 0;
				rcoor2.P2 = 0;
				break;
			}
			else
			{
				rcoor2.X = rcoor2.X + M2X0;			//新的接收机坐标=改正数+初值，下面判断，如果delt>0.001的话，返回do，将rcoor.X重新作为初值，循环计算到delt<0.001;
				rcoor2.Y = rcoor2.Y + M2Y0;
				rcoor2.Z = rcoor2.Z + M2Z0;
				//delt = rcoor2.X - M2X0;
				delt = sqrt(pow(rcoor2.X - M2X0,2.0)+pow(rcoor2.Y - M2Y0,2.0)+pow(rcoor2.Z - M2Z0,2.0));

				/*	if (fabs(delt)<0.00001)
				break;*/

			}
		}
		else if (MM2 ==0 && KK2>=4)//单BDS系统，大于4时，RMS才有值;
		{
			recei_coor_single(&rcoor2,M2_bds_coor,M2_bds_wj,&KK2,M2_BDS_SR,&GDOP2,&PDOP2);//计算接收机坐标,返回位置的改正数rcoor.X、rcoor.Y、rcoor.Z;
			if(rcoor2.X==0&&rcoor2.Y==0&&rcoor2.Z==0)//不能循环太多，比如循环39次，这里的rcoor.X==0&&rcoor.Y==0&&rcoor.Z==0，但是是正确的
			{
				rcoor2.X = 0;
				rcoor2.Y = 0;
				rcoor2.Z = 0;
				rcoor2.P1 = 0;
				rcoor2.P2 = 0;
				break;
			}
			else
			{
				rcoor2.X = rcoor2.X + M2X0;			//新的接收机坐标=改正数+初值，下面判断，如果delt>0.001的话，返回do，将rcoor.X重新作为初值，循环计算到delt<0.001;
				rcoor2.Y = rcoor2.Y + M2Y0;
				rcoor2.Z = rcoor2.Z + M2Z0;
				//delt = rcoor2.X - M2X0;
				delt = sqrt(pow(rcoor2.X - M2X0,2.0)+pow(rcoor2.Y - M2Y0,2.0)+pow(rcoor2.Z - M2Z0,2.0));

				/*if (fabs(delt)<0.00001)
				break;*/

			}
		}
		else
		{
			rcoor2.X = 0;
			rcoor2.Y = 0;
			rcoor2.Z = 0;
			rcoor2.P1 = 0;
			rcoor2.P2 = 0;
			break;
		}
		//if (rcoor2.X!=0&&fabs(delt)<0.00001)
		//	break;
	}while(delt>0.00001);

	if (rcoor2.X != 0 && (MM2 != 0 || KK2 != 0 || RR2 != 0))//160814
	{
		sate_num.KK2 = KK2;
		sate_num.MM2 = MM2;
		sate_num.RR2 = RR2;
		sate_num.ALL_GB2 = ALL_GB2;
		sate_num.delX2 = rcoor2.X;
		sate_num.delY2 = rcoor2.Y;
		sate_num.delZ2 = rcoor2.Z;
		sate_num.M2_P1 = rcoor2.P1;
		sate_num.M2_P2 = rcoor2.P2;
		sate_num.M2_P3 = rcoor2.P3;
		sate_num.GDOP2 = GDOP2;
		sate_num.PDOP2 = PDOP2;
	}

}

void CNDGNSS::NWDGNSS_MOVING_POS_MODULE_RAIM(GridAttribute GridValue,double  M_coor[],VBS_PR_CR VBPC[], DATG dg0, GEPH geph[MAXPRN_NUM],rp &rcoor2,Sate_NUM &sate_num)
{
	double	delt = 1;								//do...while()限制条件中的接收机X坐标迭代控制条件
	double	GDOP2 = 0, PDOP2 = 0;
	DATG dg[5] = { 0 };
	//int i = 0;
	dg[1] = dg0;
	BS_PR_CR BPC={0};

	//这里因为是车载，所以流动站一直在变，那么如果流动站有坐标，就用流动站坐标到各基准站的距离，如果流动站坐标为0，就用监测站坐标，一般流动站第一次坐标为0，以后都会有值，为上一次的解得的值;
	IOFH ih3[4] = { 0 };

	int IWGD=GridValue.Grid_ID;//所需的格网ID
	int pp=0;
	int nn1=0;
	if(IWGD!=99999&&VBPC[IWGD].tg.second==dg[1].tg.second)//匹配历元,流动站历元与改正数历元要相同20150807;
	{
		for(int n1 = 0 ;n1 < VBPC[IWGD].G_num; n1++)
		{
			BPC.G_PRN[n1] = VBPC[IWGD].G_PRN[n1];
			BPC.GPC[n1] = VBPC[IWGD].GPC[n1];
		}

		for(int p1 = 0 ;p1 < VBPC[IWGD].C_num; p1++)
		{
			BPC.C_PRN[p1] = VBPC[IWGD].C_PRN[p1];
			BPC.CPC[p1] = VBPC[IWGD].CPC[p1];
		}
		pp=VBPC[IWGD].C_num;
		nn1=VBPC[IWGD].G_num;





		/************▼流动站1  dg[1]计算▼↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/

		double	M2X0, M2Y0, M2Z0;							//流动站初始坐标;
		double	M2g_swj, M2g_R, M2b_swj, M2b_R;
		double	M2G_XK, M2G_YK, M2G_ZK, M2B_XK, M2B_YK, M2B_ZK;	//初始坐标;
		int		MM2, KK2, ALL_GB2;
		double	M2gps_wj[32] = { 0 }, M2GPS_SR[32] = { 0 };	//流动站解算的gps伪距&近似距离——存储值;
		double	M2bds_wj[35] = { 0 }, M2BDS_SR[35] = { 0 };	//流动站解算的bds伪距&近似距离——存储值;
		int		M2GPRN[32] = { 0 };						//流动站gpsPRN号——存储值;
		int		M2BPRN[35] = { 0 };						//流动站bdsPRN号——存储值;
		sp		M2gps_coor = { 0 }, M2bds_coor = { 0 };		//流动站解算的gps与bds的卫星坐标——存储值;

		double	M2_gps_wj[32] = { 0 }, M2_GPS_SR[32] = { 0 };//流动站最终解算;
		double	M2_bds_wj[35] = { 0 }, M2_BDS_SR[35] = { 0 };//流动站最终解算;
		int		M2_GPRN[32] = { 0 };					//流动站最终解算;
		int		M2_BPRN[35] = { 0 };					//流动站最终解算;
		sp		M2_gps_coor = { 0 }, M2_bds_coor = { 0 };	//流动站最终解算;


		double check2_gps[32] = { 0 }, check2_bds[35] = { 0 };//检测伪距改正输出;
		//int	m2 = 0, k2 = 0;								//循环回代置零;
		//rp		rcoor2={0};
		rcoor2.X = M_coor[0];
		rcoor2.Y = M_coor[1];
		rcoor2.Z = M_coor[2];


		int xunhuan=0;
		do		//最多循环10次跳出，代替do。。。。while;
		{ 


			if( xunhuan>14)	{break;}		//最多循环10次跳出，代替do。。。。while;
			xunhuan++;
			int	m2 = 0, k2 = 0;								//循环回代置零;
			M2X0 = rcoor2.X;								//用于循环回代;
			M2Y0 = rcoor2.Y;
			M2Z0 = rcoor2.Z;

			for (int ii = 0; ii<dg[1].nsat; ii++)				//基于流动站计算卫星位置及伪距&卫地距;
			{
				if(dg[1].prn[ii] >= 1 &&dg[1].prn[ii] < 33)
				{
					M2g_swj = 0, M2g_R = 0;
					M2G_XK = 0, M2G_YK = 0, M2G_ZK = 0;
					GNSS_POS_MODULE(geph, dg, 1, M2X0, M2Y0, M2Z0, &M2g_swj, &M2g_R, &M2G_XK, &M2G_YK, &M2G_ZK, ii, 1);//dg后面的参数为站号,为了配合dg【】中的号;
					if (M2g_swj != 0 && M2g_R != 0)
					{
						M2gps_wj[m2] = M2g_swj;
						M2GPS_SR[m2] = M2g_R;
						M2GPRN[m2] = dg[1].prn[ii];
						M2gps_coor.X[m2] = M2G_XK;
						M2gps_coor.Y[m2] = M2G_YK;
						M2gps_coor.Z[m2] = M2G_ZK;

						check2_gps[m2] = M2g_R - M2g_swj;					//检测改正值正确与否,与BDS的改正值对比,注意：检测时要加入卫星钟差，以使对比与BDS的改正值是否一致,正确的应该和BDS是一致的;
						m2++;											//m为可利用GPS卫星数目
					}
				}
				if(dg[1].prn[ii] >= 33 && dg[1].prn[ii] < 57)
					continue;
				if(dg[1].prn[ii] >= 161 && dg[1].prn[ii] < 181)
				{
					M2b_swj = 0, M2b_R = 0;
					M2B_XK = 0, M2B_YK = 0, M2B_ZK = 0;
					GNSS_POS_MODULE(geph, dg, 1, M2X0, M2Y0, M2Z0, &M2b_swj, &M2b_R, &M2B_XK, &M2B_YK, &M2B_ZK, ii, 2);//dg后面的参数为站号,为了配合dg【】中的号;
					if (M2b_swj != 0 && M2b_R != 0)
					{
						M2bds_wj[k2] = M2b_swj;
						M2BDS_SR[k2] = M2b_R;
						M2BPRN[k2] = dg[1].prn[ii];
						M2bds_coor.X[k2] = M2B_XK;
						M2bds_coor.Y[k2] = M2B_YK;
						M2bds_coor.Z[k2] = M2B_ZK;

						check2_bds[k2] = M2b_R - M2b_swj;			//检测改正值正确与否,与GPS的改正值对比,注意：检测时要加入卫星钟差，以使对比与GPS的改正值是否一致,正确的应该和GPS是一致的;
						k2++;								//m为可利用GPS卫星数目
					}
				}
			}


			/********▼匹配伪距改正数▼********/;
			int mm2 = 0, kk2 = 0;							//该历元中流动站和改正数相匹配的数;
			for (int ii = 0; ii<m2; ii++)				//匹配从3个基准站传过来的通过反距离加权后的GPS伪距改正值;
			{
				for (int jj = 0; jj<nn1; jj++)
				{
					//if (M2GPRN[ii]==BPC.G_PRN[jj]&&BPC.C_PRN[jj]!=bad_BPRN[0]&&BPC.C_PRN[jj]!=bad_BPRN[1]&&BPC.C_PRN[jj]!=bad_BPRN[2]&&BPC.C_PRN[jj]!=bad_BPRN[3]&&BPC.C_PRN[jj]!=bad_BPRN[4])
					if (M2GPRN[ii] == BPC.G_PRN[jj])
					{
						M2_gps_wj[mm2] = M2gps_wj[ii] + BPC.GPC[jj];
						M2_GPS_SR[mm2] = M2GPS_SR[ii];
						M2_GPRN[mm2] = M2GPRN[ii];
						M2_gps_coor.X[mm2] = M2gps_coor.X[ii];
						M2_gps_coor.Y[mm2] = M2gps_coor.Y[ii];
						M2_gps_coor.Z[mm2] = M2gps_coor.Z[ii];
						mm2++;
						break;
					}
				}
			}
			for (int ii = 0; ii<k2; ii++)				//匹配从3个基准站传过来的的通过反距离加权后的BDS伪距改正值;
			{
				for (int jj = 0; jj<pp; jj++)
				{
					//if (M2BPRN[ii]==BPC.C_PRN[jj]&&BPC.C_PRN[jj]!=bad_BPRN[0]&&BPC.C_PRN[jj]!=bad_BPRN[1]&&BPC.C_PRN[jj]!=bad_BPRN[2]&&BPC.C_PRN[jj]!=bad_BPRN[3]&&BPC.C_PRN[jj]!=bad_BPRN[4])
					if (M2BPRN[ii] == BPC.C_PRN[jj])
					{
						M2_bds_wj[kk2] = M2bds_wj[ii] + BPC.CPC[jj];
						M2_BDS_SR[kk2] = M2BDS_SR[ii];
						M2_BPRN[kk2] = M2BPRN[ii];
						M2_bds_coor.X[kk2] = M2bds_coor.X[ii];
						M2_bds_coor.Y[kk2] = M2bds_coor.Y[ii];
						M2_bds_coor.Z[kk2] = M2bds_coor.Z[ii];
						kk2++;
						break;
					}
				}
			}

			/************▼定位解算▼↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
			MM2 = mm2, KK2 = kk2;
			ALL_GB2 = MM2 + KK2;
			if (ALL_GB2 >= 5 && MM2>0 && KK2>0)
			{
				recei_coor(&rcoor2, M2_gps_coor, M2_gps_wj, M2_GPS_SR, M2_bds_coor, M2_bds_wj, M2_BDS_SR, ALL_GB2, MM2, KK2, &GDOP2, &PDOP2, dg[1].tg.second);//计算接收机坐标,返回位置的改正数rcoor.X、rcoor.Y、rcoor.Z;
				if (rcoor2.X != 0 && rcoor2.Y != 0 && rcoor2.Z != 0)
				{
					rcoor2.X = rcoor2.X + M2X0;			//新的接收机坐标=改正数+初值，下面判断，如果delt>0.001的话，返回do，将rcoor.X重新作为初值，循环计算到delt<0.001;
					rcoor2.Y = rcoor2.Y + M2Y0;
					rcoor2.Z = rcoor2.Z + M2Z0;
					//delt = rcoor2.X - M2X0;
					delt = sqrt(pow(rcoor2.X - M2X0,2.0)+pow(rcoor2.Y - M2Y0,2.0)+pow(rcoor2.Z - M2Z0,2.0));

					/*if (fabs(delt)<0.00001)
					break;*/
				}
				else
				{
					rcoor2.X = 0;
					rcoor2.Y = 0;
					rcoor2.Z = 0;
					rcoor2.P1 = 0;
					rcoor2.P2 = 0;
					break;
				}
			}
			else if (MM2 >= 4 && KK2==0)//单GPS系统，大于4时，RMS才有值;
			{
				recei_coor_single(&rcoor2,M2_gps_coor,M2_gps_wj,&MM2,M2_GPS_SR,&GDOP2,&PDOP2);//计算接收机坐标,返回位置的改正数rcoor.X、rcoor.Y、rcoor.Z;
				if(rcoor2.X==0&&rcoor2.Y==0&&rcoor2.Z==0)//不能循环太多，比如循环39次，这里的rcoor.X==0&&rcoor.Y==0&&rcoor.Z==0，但是是正确的
				{
					rcoor2.X = 0;
					rcoor2.Y = 0;
					rcoor2.Z = 0;
					rcoor2.P1 = 0;
					rcoor2.P2 = 0;
					break;
				}
				else
				{
					rcoor2.X = rcoor2.X + M2X0;			//新的接收机坐标=改正数+初值，下面判断，如果delt>0.001的话，返回do，将rcoor.X重新作为初值，循环计算到delt<0.001;
					rcoor2.Y = rcoor2.Y + M2Y0;
					rcoor2.Z = rcoor2.Z + M2Z0;
					//delt = rcoor2.X - M2X0;
					delt = sqrt(pow(rcoor2.X - M2X0,2.0)+pow(rcoor2.Y - M2Y0,2.0)+pow(rcoor2.Z - M2Z0,2.0));

					/*	if (fabs(delt)<0.00001)
					break;*/

				}
			}
			else if (MM2 ==0 && KK2>=4)//单BDS系统，大于4时，RMS才有值;
			{
				recei_coor_single(&rcoor2,M2_bds_coor,M2_bds_wj,&KK2,M2_BDS_SR,&GDOP2,&PDOP2);//计算接收机坐标,返回位置的改正数rcoor.X、rcoor.Y、rcoor.Z;
				if(rcoor2.X==0&&rcoor2.Y==0&&rcoor2.Z==0)//不能循环太多，比如循环39次，这里的rcoor.X==0&&rcoor.Y==0&&rcoor.Z==0，但是是正确的
				{
					rcoor2.X = 0;
					rcoor2.Y = 0;
					rcoor2.Z = 0;
					rcoor2.P1 = 0;
					rcoor2.P2 = 0;
					break;
				}
				else
				{
					rcoor2.X = rcoor2.X + M2X0;			//新的接收机坐标=改正数+初值，下面判断，如果delt>0.001的话，返回do，将rcoor.X重新作为初值，循环计算到delt<0.001;
					rcoor2.Y = rcoor2.Y + M2Y0;
					rcoor2.Z = rcoor2.Z + M2Z0;
					//delt = rcoor2.X - M2X0;
					delt = sqrt(pow(rcoor2.X - M2X0,2.0)+pow(rcoor2.Y - M2Y0,2.0)+pow(rcoor2.Z - M2Z0,2.0));

					/*if (fabs(delt)<0.00001)
					break;*/

				}
			}
			else
			{
				rcoor2.X = 0;
				rcoor2.Y = 0;
				rcoor2.Z = 0;
				rcoor2.P1 = 0;
				rcoor2.P2 = 0;
				break;
			}
			//if (rcoor2.X!=0&&fabs(delt)<0.00001)
			//	break;
		}while(delt>0.00001);
		rp rcoor_raim=rcoor2;
		int MM_raim=MM2,KK_raim=KK2;
		double GDOP_raim=0.0,PDOP_raim=0.0;
		int chaoxian_num = 0;						//监测站监测卫星，监测有几个超限卫星chaoxian_num;
		int bad_GPRN[20] = { 0 }, bad_BPRN[20] = { 0 };	//存储坏的GPS卫星和坏的BDS卫星;
		int B_bad_num = 0, G_bad_num = 0;								//BDS、GPS残差超限的个数;
		int T = MM_raim + KK_raim;						//多系统定位总的卫星个数Totle;
		//int i1, j1;									//为了进行循环;
		int final_N, final_P;
		double X_raim0, Y_raim0, Z_raim0;
		X_raim0 = rcoor_raim.X;
		Y_raim0 = rcoor_raim.Y;
		Z_raim0 = rcoor_raim.Z;

		/************▼完备性监测▼↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
		double	*ll = new	double[T]();		//课本P57参数  等加以double	(*ll)[1]=	 new	double[T][1];
		double	*mm = new	double[T]();
		double	*nn = new	double[T]();
		double	*L = new	double[T]();
		double	*A = new	double[T * 5]();		//状态矩阵A;
		double	*AT = new	double[5 * T]();		//状态矩阵A的转置;
		double	*P = new	double[T*T]();		//权矩阵P;              ()是对动态内存进行初始化
		double	*ATP = new	double[5 * T]();		//A的转置乘以P;
		double	*ATPA = new	double[5 * 5]();		//A的转置乘以P乘以A;
		double	*inv_ATPA = new	double[5 * 5]();		//(A的转置乘以P乘以A)的逆;
		double	*ATPL = new	double[5]();		//A的转置乘以P乘以L;
		double	*result = new	double[5]();		//(A的转置乘以P乘以A)乘以(A的转置乘以P乘以L)，(inv_ATPA)(ATPL);


		double	*AX = new	double[T]();		//A乘以X;
		double  *V = new	double[T]();		//V=AX-L
		double	*VT = new	double[1 * T]();
		double	*VTP = new	double[1 * T]();
		double	*VTPV = new	double[T * 1]();

		///////////////////////////////////////////列法方程;

		//cout<<"系数矩阵B和L"<<endl;																	//
		for (int i1 = 0; i1<MM_raim; i1++)
		{
			ll[i1] = (M2_gps_coor.X[i1] - rcoor_raim.X) / M2_GPS_SR[i1];
			mm[i1] = (M2_gps_coor.Y[i1] - rcoor_raim.Y) / M2_GPS_SR[i1];
			nn[i1] = (M2_gps_coor.Z[i1] - rcoor_raim.Z) / M2_GPS_SR[i1];
			A[i1 * 5 + 0] = ll[i1];
			A[i1 * 5 + 1] = mm[i1];
			A[i1 * 5 + 2] = nn[i1];
			A[i1 * 5 + 3] = -1;
			//A[i*5+4]=0;								//初始化了就不需要了
			L[i1] = M2_GPS_SR[i1] - M2_gps_wj[i1];

			//printf("%8.3f%8.3f%8.3f%8.3f%8.3f%16.3f\n",A[i*5+0],A[i*5+1],A[i*5+2],A[i*5+3],A[i*5+4],L[i]);	//

			P[i1*T + i1] = 1;									//给GPS定的权
		}
		for (int j1 = MM_raim; j1<T; j1++)
		{
			ll[j1] = (M2_bds_coor.X[j1 - MM_raim] - rcoor_raim.X) / M2_BDS_SR[j1 - MM_raim];
			mm[j1] = (M2_bds_coor.Y[j1 - MM_raim] - rcoor_raim.Y) / M2_BDS_SR[j1 - MM_raim];
			nn[j1] = (M2_bds_coor.Z[j1 - MM_raim] - rcoor_raim.Z) / M2_BDS_SR[j1 - MM_raim];
			A[j1 * 5 + 0] = ll[j1];
			A[j1 * 5 + 1] = mm[j1];
			A[j1 * 5 + 2] = nn[j1];
			//A[j*5+3]=0;								//初始化了就不需要了;
			A[j1 * 5 + 4] = -1;
			L[j1] = M2_BDS_SR[j1 - MM_raim] - M2_bds_wj[j1 - MM_raim];

			//printf("%8.3f%8.3f%8.3f%8.3f%8.3f%16.3f\n",A[j*5+0],A[j*5+1],A[j*5+2],A[j*5+3],A[j*5+4],L[j]);	//

			P[j1*T + j1] = 1;									//给BDS定的权
		}

		///////////////////////////////////////////通过函数的指针进行矩阵的运算，传出需要的矩阵;
		M_Tra(T, 5, A, AT);							//矩阵转置	A的转置		传出AT;
		M_Mul(5, T, T, AT, P, ATP);						//矩阵相乘	AT乘P		传出ATP;
		M_Mul(5, T, 5, ATP, A, ATPA);					//			ATP乘A		传出ATPA;
		M_Inv(5, ATPA, inv_ATPA);						//矩阵求逆	ATPA的逆		传出inv_ATPA;
		M_Mul(5, T, 1, ATP, L, ATPL);					//			ATP乘L		传出ATPL;
		M_Mul(5, 5, 1, inv_ATPA, ATPL, result);			//			inv_ATPA乘ATPL传出result;

		//cout<<inv_ATPA[1]<<inv_ATPA[2]<<inv_ATPA[3]<<inv_ATPA[4]<<inv_ATPA[5]<<endl;
		//cout<<ATPL[1]<<ATPL[2]<<ATPL[3]<<ATPL[4]<<ATPL[5]<<endl;
		if (inv_ATPA != NULL)
		{
			rcoor_raim.X = result[0];
			rcoor_raim.Y = result[1];
			rcoor_raim.Z = result[2];
			rcoor_raim.P1 = result[3];
			rcoor_raim.P2 = result[4];

			for (int i = 0; i<5; i++)
				GDOP_raim += inv_ATPA[i * 5 + i];
			sate_num.GDOP_raim = sqrt(GDOP_raim);
			for (int i = 0; i<3; i++)
				PDOP_raim += inv_ATPA[i * 5 + i];
			sate_num.PDOP_raim = sqrt(PDOP_raim);
		}
		else
		{
			rcoor_raim.X = 0;
			rcoor_raim.Y = 0;
			rcoor_raim.Z = 0;
			rcoor_raim.P1 = 0;
			rcoor_raim.P2 = 0;
			//printf("这个历元数据无法求解!\n");
			//system("pause");
		}

		double X[5][1];
		X[0][0] = rcoor_raim.X;
		X[0][1] = rcoor_raim.Y;
		X[0][2] = rcoor_raim.Z;
		X[0][3] = rcoor_raim.P1;
		X[0][4] = rcoor_raim.P2;
		//double	*AX=	new	double[T]();			//A乘以X;
		M_Mul(T, 5, 1, A, X[0], AX);							//矩阵相乘;
		//double  *V=		new	double[T]();			//V=AX-L

		for (int p = 0; p<T; p++)
		{
			V[p] = AX[p] - L[p];
		}
		//double *VT=		new	double[1*T]();
		//double *VTP=	new	double[1*T]();
		//double *VTPV=	new	double[T*1]();

		M_Tra(T, 1, V, VT);								//矩阵转置	A的转置		传出AT;
		M_Mul(1, T, T, VT, P, VTP);							//矩阵相乘	AT乘P		传出ATP;
		M_Mul(1, T, 1, VTP, V, VTPV);
		double RMS_raim = sqrt(*VTPV / (T - 5));
		double w[32];
		for (int i = 0; i<T; i++)
		{
			w[i] = fabs(V[i]) / (RMS_raim*sqrt((T - 1.0) / T));
			//printf("%16.8f\n",w[i]);				//
		}
		int n_s=0;
		int NNN,PPP;

		for(int i=0;i<T;i++)
		{
			if(w[i]> 3)
			{
				//w1=w[i];
				n_s=i;
				NNN = MM_raim;
				PPP = KK_raim;
				if (n_s>NNN - 1)			//说明是BDS卫星的
				{
					bad_BPRN[chaoxian_num] = M2_BPRN[n_s - NNN];//如果GPS7颗，BDS9颗，现在pp=8，也就是w中第9个，那么就是BDS卫星的第2个对应于1，即8-7=1;
					//chaoxian_num++;
					//for(int j=1;j<5;j++)//四个基准站，依次消除坏星;
					//{
					for (int m=0;m<VBPC[IWGD].C_num;m++)//从0开始依次比对prn
					{
						if (bad_BPRN[chaoxian_num]==VBPC[IWGD].C_PRN[m])//当prn相同时就消除这颗卫星对应的内容;
						{
							for (int s = m; s<VBPC[IWGD].C_num; s++)//从坏星开始将后一个星内容覆盖前一个卫星内容;
							{
								VBPC[IWGD].C_PRN[s]=VBPC[IWGD].C_PRN[s+1];
								VBPC[IWGD].CPC[s]=VBPC[IWGD].CPC[s+1];
							}
							VBPC[IWGD].C_num--;
							break;
						}
					}
					//}
					B_bad_num++;
					KK_raim = PPP - 1;		//新的BDS卫星个数
					chaoxian_num++;
				}
				else					//说明是GPS卫星的
				{
					bad_GPRN[chaoxian_num] = M2_GPRN[n_s];
					//for(int j=1;j<5;j++)//四个基准站，依次消除坏星;
					//	{
					for (int m=0;m<VBPC[IWGD].G_num;m++)//从0开始依次比对prn
					{
						if (bad_GPRN[chaoxian_num]==VBPC[IWGD].G_PRN[m])//当prn相同时就消除这颗卫星对应的内容;
						{
							for (int s = m; s<VBPC[IWGD].G_num; s++)//从坏星开始将后一个星内容覆盖前一个卫星内容;
							{
								VBPC[IWGD].G_PRN[s]=VBPC[IWGD].G_PRN[s+1];
								VBPC[IWGD].GPC[s]=VBPC[IWGD].GPC[s+1];
							}
							VBPC[IWGD].G_num--;
							break;
						}
					}
					//}
					G_bad_num++;
					MM_raim = NNN - 1;		//新的GPS卫星个数
					chaoxian_num++;
				}
			}
		}				
		NWDGNSS_MOVING_POS_MODULE(GridValue,M_coor,VBPC, dg[1],geph,rcoor2,sate_num);//再次计算;
	}
	/*if (rcoor2.X != 0 && MM2 != 0 && KK2 != 0)
	{
	sate_num.KK2 = KK_raim;
	sate_num.MM2 = MM_raim;
	sate_num.ALL_GB2 = T;
	sate_num.delX2 = rcoor2.X;
	sate_num.delY2 = rcoor2.Y;
	sate_num.delZ2 = rcoor2.Z;
	sate_num.M2_P1 = rcoor2.P1;
	sate_num.M2_P2 = rcoor2.P2;
	sate_num.GDOP2 = GDOP_raim;
	sate_num.PDOP2 = PDOP_raim;
	}*/

}


void CNDGNSS::NWDGNSS_MOVING_POS_MODULE(GridAttribute GridValue,double  M_coor[],VBS_PR_CR VBPC[], DATG dg0, GEPH geph[MAXPRN_NUM], rp &rcoor2,Sate_NUM &sate_num)
{
	double	delt = 1;								//do...while()限制条件中的接收机X坐标迭代控制条件
	double	GDOP2 = 0, PDOP2 = 0;
	DATG dg[5] = { 0 };
	//int i = 0;
	dg[1] = dg0;
	BS_PR_CR BPC={0};
	//这里因为是车载，所以流动站一直在变，那么如果流动站有坐标，就用流动站坐标到各基准站的距离，如果流动站坐标为0，就用监测站坐标，一般流动站第一次坐标为0，以后都会有值，为上一次的解得的值;
	IOFH ih3[4] = { 0 };

	int pp=0;
	int nn1=0;
	int IWGD=GridValue.Grid_ID;
	if(IWGD!=99999)
	{
		for(int n1 = 0 ;n1 < VBPC[IWGD].G_num; n1++)
		{
			BPC.G_PRN[n1] = VBPC[IWGD].G_PRN[n1];
			BPC.GPC[n1] = VBPC[IWGD].GPC[n1];
		}

		for(int p1 = 0 ;p1 < VBPC[IWGD].C_num; p1++)
		{
			BPC.C_PRN[p1] = VBPC[IWGD].C_PRN[p1];
			BPC.CPC[p1] = VBPC[IWGD].CPC[p1];
		}
		pp=VBPC[IWGD].C_num;
		nn1=VBPC[IWGD].G_num;
	}


	/************▼流动站▼↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/

	double	M2X0, M2Y0, M2Z0;							//流动站初始坐标;
	double	M2g_swj, M2g_R, M2b_swj, M2b_R;
	double	M2G_XK, M2G_YK, M2G_ZK, M2B_XK, M2B_YK, M2B_ZK;	//初始坐标;
	int		MM2, KK2, ALL_GB2;
	//rp		rcoor2={0};
	rcoor2.X = M_coor[0];
	rcoor2.Y = M_coor[1];
	rcoor2.Z = M_coor[2];


	int xunhuan=0;
	do		//最多循环10次跳出，代替do。。。。while;
	{ 


		if( xunhuan>14)	{break;}		//最多循环10次跳出，代替do。。。。while;
		xunhuan++;

		double	M2gps_wj[32] = { 0 }, M2GPS_SR[32] = { 0 };	//流动站解算的gps伪距&近似距离——存储值;
		double	M2bds_wj[35] = { 0 }, M2BDS_SR[35] = { 0 };	//流动站解算的bds伪距&近似距离——存储值;
		int		M2GPRN[32] = { 0 };						//流动站gpsPRN号——存储值;
		int		M2BPRN[35] = { 0 };						//流动站bdsPRN号——存储值;
		sp		M2gps_coor = { 0 }, M2bds_coor = { 0 };		//流动站解算的gps与bds的卫星坐标——存储值;

		double	M2_gps_wj[32] = { 0 }, M2_GPS_SR[32] = { 0 };//流动站最终解算;
		double	M2_bds_wj[35] = { 0 }, M2_BDS_SR[35] = { 0 };//流动站最终解算;
		int		M2_GPRN[32] = { 0 };					//流动站最终解算;
		int		M2_BPRN[35] = { 0 };					//流动站最终解算;
		sp		M2_gps_coor = { 0 }, M2_bds_coor = { 0 };	//流动站最终解算;


		double check2_gps[32] = { 0 }, check2_bds[35] = { 0 };//检测伪距改正输出;
		int	m2 = 0, k2 = 0;								//循环回代置零;
		M2X0 = rcoor2.X;								//用于循环回代;
		M2Y0 = rcoor2.Y;
		M2Z0 = rcoor2.Z;

		for (int ii = 0; ii<dg[1].nsat; ii++)				//基于流动站计算卫星位置及伪距&卫地距;
		{
			if(dg[1].prn[ii] >= 1 &&dg[1].prn[ii] < 33)
			{
				M2g_swj = 0, M2g_R = 0;
				M2G_XK = 0, M2G_YK = 0, M2G_ZK = 0;
				GNSS_POS_MODULE(geph, dg, 1, M2X0, M2Y0, M2Z0, &M2g_swj, &M2g_R, &M2G_XK, &M2G_YK, &M2G_ZK, ii, 1);//dg后面的参数为站号,为了配合dg【】中的号;
				if (M2g_swj != 0 && M2g_R != 0)
				{
					M2gps_wj[m2] = M2g_swj;
					M2GPS_SR[m2] = M2g_R;
					M2GPRN[m2] = dg[1].prn[ii];
					M2gps_coor.X[m2] = M2G_XK;
					M2gps_coor.Y[m2] = M2G_YK;
					M2gps_coor.Z[m2] = M2G_ZK;

					check2_gps[m2] = M2g_R - M2g_swj;					//检测改正值正确与否,与BDS的改正值对比,注意：检测时要加入卫星钟差，以使对比与BDS的改正值是否一致,正确的应该和BDS是一致的;
					m2++;											//m为可利用GPS卫星数目
				}
			}
			if(dg[1].prn[ii] >= 33 && dg[1].prn[ii] < 57)
				continue;
			if(dg[1].prn[ii] >= 161 && dg[1].prn[ii] < 181)
			{
				M2b_swj = 0, M2b_R = 0;
				M2B_XK = 0, M2B_YK = 0, M2B_ZK = 0;
				GNSS_POS_MODULE(geph, dg, 1, M2X0, M2Y0, M2Z0, &M2b_swj, &M2b_R, &M2B_XK, &M2B_YK, &M2B_ZK, ii, 2);//dg后面的参数为站号,为了配合dg【】中的号;
				if (M2b_swj != 0 && M2b_R != 0)
				{
					M2bds_wj[k2] = M2b_swj;
					M2BDS_SR[k2] = M2b_R;
					M2BPRN[k2] = dg[1].prn[ii];
					M2bds_coor.X[k2] = M2B_XK;
					M2bds_coor.Y[k2] = M2B_YK;
					M2bds_coor.Z[k2] = M2B_ZK;

					check2_bds[k2] = M2b_R - M2b_swj;			//检测改正值正确与否,与GPS的改正值对比,注意：检测时要加入卫星钟差，以使对比与GPS的改正值是否一致,正确的应该和GPS是一致的;
					k2++;								//m为可利用GPS卫星数目
				}
			}
		}

		/************▼匹配历元改正数▼↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
		int mm2 = 0, kk2 = 0;							//该历元中流动站和改正数相匹配的数;
		for (int ii = 0; ii<m2; ii++)				//匹配从3个基准站传过来的通过反距离加权后的GPS伪距改正值;
		{
			for (int jj = 0; jj<nn1; jj++)
			{
				//if (M2GPRN[ii]==BPC.G_PRN[jj]&&BPC.C_PRN[jj]!=bad_BPRN[0]&&BPC.C_PRN[jj]!=bad_BPRN[1]&&BPC.C_PRN[jj]!=bad_BPRN[2]&&BPC.C_PRN[jj]!=bad_BPRN[3]&&BPC.C_PRN[jj]!=bad_BPRN[4])
				if (M2GPRN[ii] == BPC.G_PRN[jj])
				{
					M2_gps_wj[mm2] = M2gps_wj[ii] + BPC.GPC[jj];
					M2_GPS_SR[mm2] = M2GPS_SR[ii];
					M2_GPRN[mm2] = M2GPRN[ii];
					M2_gps_coor.X[mm2] = M2gps_coor.X[ii];
					M2_gps_coor.Y[mm2] = M2gps_coor.Y[ii];
					M2_gps_coor.Z[mm2] = M2gps_coor.Z[ii];
					mm2++;
					break;
				}
			}
		}
		for (int ii = 0; ii<k2; ii++)				//匹配从3个基准站传过来的的通过反距离加权后的BDS伪距改正值;
		{
			for (int jj = 0; jj<pp; jj++)
			{
				//if (M2BPRN[ii]==BPC.C_PRN[jj]&&BPC.C_PRN[jj]!=bad_BPRN[0]&&BPC.C_PRN[jj]!=bad_BPRN[1]&&BPC.C_PRN[jj]!=bad_BPRN[2]&&BPC.C_PRN[jj]!=bad_BPRN[3]&&BPC.C_PRN[jj]!=bad_BPRN[4])
				if (M2BPRN[ii] == BPC.C_PRN[jj])
				{
					M2_bds_wj[kk2] = M2bds_wj[ii] + BPC.CPC[jj];
					M2_BDS_SR[kk2] = M2BDS_SR[ii];
					M2_BPRN[kk2] = M2BPRN[ii];
					M2_bds_coor.X[kk2] = M2bds_coor.X[ii];
					M2_bds_coor.Y[kk2] = M2bds_coor.Y[ii];
					M2_bds_coor.Z[kk2] = M2bds_coor.Z[ii];
					kk2++;
					break;
				}
			}
		}

		/************▼定位解算▼↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
		MM2 = mm2, KK2 = kk2;
		ALL_GB2 = MM2 + KK2;
		if (ALL_GB2 >= 5 && MM2>0 && KK2>0)//双系统;
		{
			recei_coor(&rcoor2, M2_gps_coor, M2_gps_wj, M2_GPS_SR, M2_bds_coor, M2_bds_wj, M2_BDS_SR, ALL_GB2, MM2, KK2, &GDOP2, &PDOP2, dg[1].tg.second);//计算接收机坐标,返回位置的改正数rcoor.X、rcoor.Y、rcoor.Z;
			if (rcoor2.X != 0 && rcoor2.Y != 0 && rcoor2.Z != 0)
			{
				rcoor2.X = rcoor2.X + M2X0;			//新的接收机坐标=改正数+初值，下面判断，如果delt>0.001的话，返回do，将rcoor.X重新作为初值，循环计算到delt<0.001;
				rcoor2.Y = rcoor2.Y + M2Y0;
				rcoor2.Z = rcoor2.Z + M2Z0;
				//delt = rcoor2.X - M2X0;
				delt = sqrt(pow(rcoor2.X - M2X0,2.0)+pow(rcoor2.Y - M2Y0,2.0)+pow(rcoor2.Z - M2Z0,2.0));

				/*if (fabs(delt)<0.00001)
				break;*/
			}
			else
			{
				rcoor2.X = 0;
				rcoor2.Y = 0;
				rcoor2.Z = 0;
				rcoor2.P1 = 0;
				rcoor2.P2 = 0;
				break;
			}
		}
		else if (MM2 >= 4 && KK2==0)//单GPS系统，大于4时，RMS才有值;
		{
			recei_coor_single(&rcoor2,M2_gps_coor,M2_gps_wj,&MM2,M2_GPS_SR,&GDOP2,&PDOP2);//计算接收机坐标,返回位置的改正数rcoor.X、rcoor.Y、rcoor.Z;
			if(rcoor2.X==0&&rcoor2.Y==0&&rcoor2.Z==0)//不能循环太多，比如循环39次，这里的rcoor.X==0&&rcoor.Y==0&&rcoor.Z==0，但是是正确的
			{
				rcoor2.X = 0;
				rcoor2.Y = 0;
				rcoor2.Z = 0;
				rcoor2.P1 = 0;
				rcoor2.P2 = 0;
				break;
			}
			else
			{
				rcoor2.X = rcoor2.X + M2X0;			//新的接收机坐标=改正数+初值，下面判断，如果delt>0.001的话，返回do，将rcoor.X重新作为初值，循环计算到delt<0.001;
				rcoor2.Y = rcoor2.Y + M2Y0;
				rcoor2.Z = rcoor2.Z + M2Z0;
				//delt = rcoor2.X - M2X0;
				delt = sqrt(pow(rcoor2.X - M2X0,2.0)+pow(rcoor2.Y - M2Y0,2.0)+pow(rcoor2.Z - M2Z0,2.0));

				/*	if (fabs(delt)<0.00001)
				break;*/

			}
		}
		else if (MM2 ==0 && KK2>=4)//单BDS系统，大于4时，RMS才有值;
		{
			recei_coor_single(&rcoor2,M2_bds_coor,M2_bds_wj,&KK2,M2_BDS_SR,&GDOP2,&PDOP2);//计算接收机坐标,返回位置的改正数rcoor.X、rcoor.Y、rcoor.Z;
			if(rcoor2.X==0&&rcoor2.Y==0&&rcoor2.Z==0)//不能循环太多，比如循环39次，这里的rcoor.X==0&&rcoor.Y==0&&rcoor.Z==0，但是是正确的
			{
				rcoor2.X = 0;
				rcoor2.Y = 0;
				rcoor2.Z = 0;
				rcoor2.P1 = 0;
				rcoor2.P2 = 0;
				break;
			}
			else
			{
				rcoor2.X = rcoor2.X + M2X0;			//新的接收机坐标=改正数+初值，下面判断，如果delt>0.001的话，返回do，将rcoor.X重新作为初值，循环计算到delt<0.001;
				rcoor2.Y = rcoor2.Y + M2Y0;
				rcoor2.Z = rcoor2.Z + M2Z0;
				//delt = rcoor2.X - M2X0;
				delt = sqrt(pow(rcoor2.X - M2X0,2.0)+pow(rcoor2.Y - M2Y0,2.0)+pow(rcoor2.Z - M2Z0,2.0));

				/*if (fabs(delt)<0.00001)
				break;*/

			}
		}
		else
		{
			rcoor2.X = 0;
			rcoor2.Y = 0;
			rcoor2.Z = 0;
			rcoor2.P1 = 0;
			rcoor2.P2 = 0;
			break;
		}
		//if (rcoor2.X!=0&&fabs(delt)<0.00001)
		//	break;
	}while(delt>0.00001);

	if (rcoor2.X != 0 && MM2 != 0 && KK2 != 0)
	{
		sate_num.KK2 = KK2;
		sate_num.MM2 = MM2;
		sate_num.ALL_GB2 = ALL_GB2;
		sate_num.delX2 = rcoor2.X;
		sate_num.delY2 = rcoor2.Y;
		sate_num.delZ2 = rcoor2.Z;
		sate_num.M2_P1 = rcoor2.P1;
		sate_num.M2_P2 = rcoor2.P2;
		sate_num.GDOP2 = GDOP2;
		sate_num.PDOP2 = PDOP2;
	}

}

int CNDGNSS::NWDGNSS_MONITOR_POS_MODULE_RAIM(GridAttribute GridValue,VBS_PR_CR VBPC[], DATG dg0[], GEPH geph[MAXPRN_NUM], IOFH ih0[],Sate_NUM sate_num[])
{
	//利用流动站单点定位结果判断所在网格并利用伪距改正数;

	if (GridValue.Monitor_BS_ID<=0) return -1;//该网格点没有符合监控站要求的站;
	if (fabs(VBPC[GridValue.Grid_ID].tg.second-dg0[GridValue.Monitor_BS_ID].tg.second)>5)//该网格点改正数适用历元与监控站历元不符20150807;
	{
		VBPC[GridValue.Grid_ID].G_num=0;//卫星数设为0;
		VBPC[GridValue.Grid_ID].C_num=0;
		return -1;
	}
	rp rcoor2={0};
	double	delt = 1;								//do...while()限制条件中的接收机X坐标迭代控制条件
	double	GDOP2 = 0, PDOP2 = 0;
	DATG dg[5] = { 0 };
	//int i = 0;
	dg[1] = dg0[GridValue.Monitor_BS_ID];
	BS_PR_CR BPC={0};

	IOFH ih3[4] = { 0 };
	int IWGD=GridValue.Grid_ID;//网格点ID;

	int pp=0;
	int nn1=0;
	if(IWGD!=99999)
	{
		for(int n1 = 0 ;n1 < VBPC[IWGD].G_num; n1++)
		{
			BPC.G_PRN[n1] = VBPC[IWGD].G_PRN[n1];
			BPC.GPC[n1] = VBPC[IWGD].GPC[n1];
		}

		for(int p1 = 0 ;p1 < VBPC[IWGD].C_num; p1++)
		{
			BPC.C_PRN[p1] = VBPC[IWGD].C_PRN[p1];
			BPC.CPC[p1] = VBPC[IWGD].CPC[p1];
		}

		pp=VBPC[IWGD].C_num;
		nn1=VBPC[IWGD].G_num;
	}


	/************▼监控站▼↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/

	double	M2X0, M2Y0, M2Z0;							//流动站初始坐标;
	double	M2g_swj, M2g_R, M2b_swj, M2b_R;
	double	M2G_XK, M2G_YK, M2G_ZK, M2B_XK, M2B_YK, M2B_ZK;	//初始坐标;
	int		MM2, KK2, ALL_GB2;
	//rp		rcoor2={0};
	int chaoxian_num = 0;						//监测站监测卫星，监测有几个超限卫星chaoxian_num;
	rcoor2.X = ih0[GridValue.Monitor_BS_ID].xyz[0];//用精确坐标做初始坐标;
	rcoor2.Y = ih0[GridValue.Monitor_BS_ID].xyz[1];
	rcoor2.Z = ih0[GridValue.Monitor_BS_ID].xyz[2];

	int bad_GPRN[20] = { 0 }, bad_BPRN[20] = { 0 };	//存储坏的GPS卫星和坏的BDS卫星;



	double	M2gps_wj[32] = { 0 }, M2GPS_SR[32] = { 0 };	//流动站解算的gps伪距&近似距离——存储值;
	double	M2bds_wj[35] = { 0 }, M2BDS_SR[35] = { 0 };	//流动站解算的bds伪距&近似距离——存储值;
	int		M2GPRN[32] = { 0 };						//流动站gpsPRN号——存储值;
	int		M2BPRN[35] = { 0 };						//流动站bdsPRN号——存储值;
	sp		M2gps_coor = { 0 }, M2bds_coor = { 0 };		//流动站解算的gps与bds的卫星坐标——存储值;

	double	M2_gps_wj[32] = { 0 }, M2_GPS_SR[32] = { 0 };//流动站最终解算;
	double	M2_bds_wj[35] = { 0 }, M2_BDS_SR[35] = { 0 };//流动站最终解算;
	int		M2_GPRN[32] = { 0 };					//流动站最终解算;
	int		M2_BPRN[35] = { 0 };					//流动站最终解算;
	sp		M2_gps_coor = { 0 }, M2_bds_coor = { 0 };	//流动站最终解算;

	int xunhuan=0;
	do		//最多循环10次跳出，代替do。。。。while;
	{ 


		if( xunhuan>14)	{break;}		//最多循环10次跳出，代替do。。。。while;
		xunhuan++;

		//double	M2gps_wj[32] = { 0 }, M2GPS_SR[32] = { 0 };	//流动站解算的gps伪距&近似距离——存储值;
		//double	M2bds_wj[35] = { 0 }, M2BDS_SR[35] = { 0 };	//流动站解算的bds伪距&近似距离——存储值;
		//int		M2GPRN[32] = { 0 };						//流动站gpsPRN号——存储值;
		//int		M2BPRN[35] = { 0 };						//流动站bdsPRN号——存储值;
		//sp		M2gps_coor = { 0 }, M2bds_coor = { 0 };		//流动站解算的gps与bds的卫星坐标——存储值;

		//double	M2_gps_wj[32] = { 0 }, M2_GPS_SR[32] = { 0 };//流动站最终解算;
		//double	M2_bds_wj[35] = { 0 }, M2_BDS_SR[35] = { 0 };//流动站最终解算;
		//int		M2_GPRN[32] = { 0 };					//流动站最终解算;
		//int		M2_BPRN[35] = { 0 };					//流动站最终解算;
		//sp		M2_gps_coor = { 0 }, M2_bds_coor = { 0 };	//流动站最终解算;


		double check2_gps[32] = { 0 }, check2_bds[35] = { 0 };//检测伪距改正输出;
		int	m2 = 0, k2 = 0;								//循环回代置零;
		M2X0 = rcoor2.X;								//用于循环回代;
		M2Y0 = rcoor2.Y;
		M2Z0 = rcoor2.Z;

		for (int ii = 0; ii<dg[1].nsat; ii++)				//基于流动站计算卫星位置及伪距&卫地距;
		{
			if(dg[1].prn[ii] >= 1 &&dg[1].prn[ii] < 33)
			{
				M2g_swj = 0, M2g_R = 0;
				M2G_XK = 0, M2G_YK = 0, M2G_ZK = 0;
				GNSS_POS_MODULE(geph, dg, 1, M2X0, M2Y0, M2Z0, &M2g_swj, &M2g_R, &M2G_XK, &M2G_YK, &M2G_ZK, ii, 1);//dg后面的参数为站号,为了配合dg【】中的号;
				if (M2g_swj != 0 && M2g_R != 0)
				{
					M2gps_wj[m2] = M2g_swj;
					M2GPS_SR[m2] = M2g_R;
					M2GPRN[m2] = dg[1].prn[ii];
					M2gps_coor.X[m2] = M2G_XK;
					M2gps_coor.Y[m2] = M2G_YK;
					M2gps_coor.Z[m2] = M2G_ZK;

					check2_gps[m2] = M2g_R - M2g_swj;					//检测改正值正确与否,与BDS的改正值对比,注意：检测时要加入卫星钟差，以使对比与BDS的改正值是否一致,正确的应该和BDS是一致的;
					m2++;											//m为可利用GPS卫星数目
				}
			}
			if(dg[1].prn[ii] >= 33 && dg[1].prn[ii] < 57)
				continue;
			if(dg[1].prn[ii] >= 161 && dg[1].prn[ii] < 181)
			{
				M2b_swj = 0, M2b_R = 0;
				M2B_XK = 0, M2B_YK = 0, M2B_ZK = 0;
				GNSS_POS_MODULE(geph, dg, 1, M2X0, M2Y0, M2Z0, &M2b_swj, &M2b_R, &M2B_XK, &M2B_YK, &M2B_ZK, ii, 2);//dg后面的参数为站号,为了配合dg【】中的号;
				if (M2b_swj != 0 && M2b_R != 0)
				{
					M2bds_wj[k2] = M2b_swj;
					M2BDS_SR[k2] = M2b_R;
					M2BPRN[k2] = dg[1].prn[ii];
					M2bds_coor.X[k2] = M2B_XK;
					M2bds_coor.Y[k2] = M2B_YK;
					M2bds_coor.Z[k2] = M2B_ZK;

					check2_bds[k2] = M2b_R - M2b_swj;			//检测改正值正确与否,与GPS的改正值对比,注意：检测时要加入卫星钟差，以使对比与GPS的改正值是否一致,正确的应该和GPS是一致的;
					k2++;								//m为可利用GPS卫星数目
				}
			}
		}

		/************▼匹配历元改正数▼↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
		int mm2 = 0, kk2 = 0;							//该历元中流动站和改正数相匹配的数;
		for (int ii = 0; ii<m2; ii++)				//匹配从3个基准站传过来的通过反距离加权后的GPS伪距改正值;
		{
			for (int jj = 0; jj<nn1; jj++)
			{
				//if (M2GPRN[ii]==BPC.G_PRN[jj]&&BPC.C_PRN[jj]!=bad_BPRN[0]&&BPC.C_PRN[jj]!=bad_BPRN[1]&&BPC.C_PRN[jj]!=bad_BPRN[2]&&BPC.C_PRN[jj]!=bad_BPRN[3]&&BPC.C_PRN[jj]!=bad_BPRN[4])
				if (M2GPRN[ii] == BPC.G_PRN[jj])
				{
					M2_gps_wj[mm2] = M2gps_wj[ii] + BPC.GPC[jj];
					M2_GPS_SR[mm2] = M2GPS_SR[ii];
					M2_GPRN[mm2] = M2GPRN[ii];
					M2_gps_coor.X[mm2] = M2gps_coor.X[ii];
					M2_gps_coor.Y[mm2] = M2gps_coor.Y[ii];
					M2_gps_coor.Z[mm2] = M2gps_coor.Z[ii];
					mm2++;
					break;
				}
			}
		}
		for (int ii = 0; ii<k2; ii++)				//匹配从3个基准站传过来的的通过反距离加权后的BDS伪距改正值;
		{
			for (int jj = 0; jj<pp; jj++)
			{
				//if (M2BPRN[ii]==BPC.C_PRN[jj]&&BPC.C_PRN[jj]!=bad_BPRN[0]&&BPC.C_PRN[jj]!=bad_BPRN[1]&&BPC.C_PRN[jj]!=bad_BPRN[2]&&BPC.C_PRN[jj]!=bad_BPRN[3]&&BPC.C_PRN[jj]!=bad_BPRN[4])
				if (M2BPRN[ii] == BPC.C_PRN[jj])
				{
					M2_bds_wj[kk2] = M2bds_wj[ii] + BPC.CPC[jj];
					M2_BDS_SR[kk2] = M2BDS_SR[ii];
					M2_BPRN[kk2] = M2BPRN[ii];
					M2_bds_coor.X[kk2] = M2bds_coor.X[ii];
					M2_bds_coor.Y[kk2] = M2bds_coor.Y[ii];
					M2_bds_coor.Z[kk2] = M2bds_coor.Z[ii];
					kk2++;
					break;
				}
			}
		}

		/************▼定位解算▼↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
		MM2 = mm2, KK2 = kk2;
		ALL_GB2 = MM2 + KK2;
		if (ALL_GB2 >= 5 && MM2>0 && KK2>0)//双系统;
		{
			recei_coor(&rcoor2, M2_gps_coor, M2_gps_wj, M2_GPS_SR, M2_bds_coor, M2_bds_wj, M2_BDS_SR, ALL_GB2, MM2, KK2, &GDOP2, &PDOP2, dg[1].tg.second);//计算接收机坐标,返回位置的改正数rcoor.X、rcoor.Y、rcoor.Z;
			if (rcoor2.X != 0 && rcoor2.Y != 0 && rcoor2.Z != 0)
			{
				rcoor2.X = rcoor2.X + M2X0;			//新的接收机坐标=改正数+初值，下面判断，如果delt>0.001的话，返回do，将rcoor.X重新作为初值，循环计算到delt<0.001;
				rcoor2.Y = rcoor2.Y + M2Y0;
				rcoor2.Z = rcoor2.Z + M2Z0;
				//delt = rcoor2.X - M2X0;
				delt = sqrt(pow(rcoor2.X - M2X0,2.0)+pow(rcoor2.Y - M2Y0,2.0)+pow(rcoor2.Z - M2Z0,2.0));

				/*if (fabs(delt)<0.00001)
				break;*/
			}
			else
			{
				rcoor2.X = 0;
				rcoor2.Y = 0;
				rcoor2.Z = 0;
				rcoor2.P1 = 0;
				rcoor2.P2 = 0;
				break;
			}
		}
		else if (MM2 >= 4 && KK2==0)//单GPS系统，大于4时，RMS才有值;
		{
			recei_coor_single(&rcoor2,M2_gps_coor,M2_gps_wj,&MM2,M2_GPS_SR,&GDOP2,&PDOP2);//计算接收机坐标,返回位置的改正数rcoor.X、rcoor.Y、rcoor.Z;
			if(rcoor2.X==0&&rcoor2.Y==0&&rcoor2.Z==0)//不能循环太多，比如循环39次，这里的rcoor.X==0&&rcoor.Y==0&&rcoor.Z==0，但是是正确的
			{
				rcoor2.X = 0;
				rcoor2.Y = 0;
				rcoor2.Z = 0;
				rcoor2.P1 = 0;
				rcoor2.P2 = 0;
				break;
			}
			else
			{
				rcoor2.X = rcoor2.X + M2X0;			//新的接收机坐标=改正数+初值，下面判断，如果delt>0.001的话，返回do，将rcoor.X重新作为初值，循环计算到delt<0.001;
				rcoor2.Y = rcoor2.Y + M2Y0;
				rcoor2.Z = rcoor2.Z + M2Z0;
				//delt = rcoor2.X - M2X0;
				delt = sqrt(pow(rcoor2.X - M2X0,2.0)+pow(rcoor2.Y - M2Y0,2.0)+pow(rcoor2.Z - M2Z0,2.0));

				/*	if (fabs(delt)<0.00001)
				break;*/

			}
		}
		else if (MM2 ==0 && KK2>=4)//单BDS系统，大于4时，RMS才有值;
		{
			recei_coor_single(&rcoor2,M2_bds_coor,M2_bds_wj,&KK2,M2_BDS_SR,&GDOP2,&PDOP2);//计算接收机坐标,返回位置的改正数rcoor.X、rcoor.Y、rcoor.Z;
			if(rcoor2.X==0&&rcoor2.Y==0&&rcoor2.Z==0)//不能循环太多，比如循环39次，这里的rcoor.X==0&&rcoor.Y==0&&rcoor.Z==0，但是是正确的
			{
				rcoor2.X = 0;
				rcoor2.Y = 0;
				rcoor2.Z = 0;
				rcoor2.P1 = 0;
				rcoor2.P2 = 0;
				break;
			}
			else
			{
				rcoor2.X = rcoor2.X + M2X0;			//新的接收机坐标=改正数+初值，下面判断，如果delt>0.001的话，返回do，将rcoor.X重新作为初值，循环计算到delt<0.001;
				rcoor2.Y = rcoor2.Y + M2Y0;
				rcoor2.Z = rcoor2.Z + M2Z0;
				//delt = rcoor2.X - M2X0;
				delt = sqrt(pow(rcoor2.X - M2X0,2.0)+pow(rcoor2.Y - M2Y0,2.0)+pow(rcoor2.Z - M2Z0,2.0));

				/*if (fabs(delt)<0.00001)
				break;*/

			}
		}
		else
		{
			rcoor2.X = 0;
			rcoor2.Y = 0;
			rcoor2.Z = 0;
			rcoor2.P1 = 0;
			rcoor2.P2 = 0;
			break;
		}
		//if (rcoor2.X!=0&&fabs(delt)<0.00001)
		//	break;
	}while(delt>0.00001);

	/************▼完备性▼↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
	double xyz[3]={0};//改正后坐标xyz0
	double NEU[3]={0};//,horizonD000wjcf=0
	xyz[0]=rcoor2.X;xyz[1]=rcoor2.Y;xyz[2]=rcoor2.Z;
	XYZ2NEU(ih0[GridValue.Monitor_BS_ID].xyz,xyz,NEU);//NEU4差分改正后xyz0相对于真值的NEU，用于评定精度
	//horizonD000wjcf=sqrt(NEU000wjcf[0]*NEU000wjcf[0]+NEU000wjcf[1]*NEU000wjcf[1]);//改正后水平偏差
	rp rcoor_raim=rcoor2;
	int MM_raim=MM2,KK_raim=KK2;
	double GDOP_raim=0.0,PDOP_raim=0.0;
	double aa,bb,cc;
	aa=fabs(NEU[0]);
	bb=fabs(NEU[1]);
	cc=fabs(NEU[2]);

	if(rcoor2.X!=0)
	{
		if(aa>3.0||bb>3.0/*||cc>4.0*/)//N,E,U限差224m，经过半天采集应设为112m，NEU调整160413，河北测试33,160812
		{
			int B_bad_num = 0, G_bad_num = 0;				//BDS、GPS残差超限的个数;
			int T = MM_raim + KK_raim;						//多系统定位总的卫星个数Totle;
			int i, j;									    //为了进行循环;
			int final_N, final_P;
			double X_raim0, Y_raim0, Z_raim0;
			X_raim0 = rcoor_raim.X;
			Y_raim0 = rcoor_raim.Y;
			Z_raim0 = rcoor_raim.Z;

			double xyztch[3]={0};//剔除后坐标xyz0
			double NEUtch[3]={0};//
			//int index;//是否循环计算的标志,也即是是否有粗差的标志;
			double a=0,b=0,c=0;
			do
			{
				if(chaoxian_num>10)
				{
					/*memset(Bn,0x00,sizeof(int)*200);
					memset(Bp,0x00,sizeof(int)*200);*/
					//memset(VBPC,0x00,sizeof(VBS_PR_CR)*30);	//该历元放弃20150729,VBS_PR_CR)*200很重要20150805;
					VBPC[IWGD].G_num=0;
					VBPC[IWGD].C_num=0;
					break;
				}
				//index = 0;
				double	*ll = new	double[T]();		//课本P57参数  等加以double	(*ll)[1]=	 new	double[T][1];
				double	*mm = new	double[T]();
				double	*nn = new	double[T]();
				double	*L = new	double[T]();
				double	*A = new	double[T * 5]();		//状态矩阵A;
				double	*AT = new	double[5 * T]();		//状态矩阵A的转置;
				double	*P = new	double[T*T]();		//权矩阵P;              ()是对动态内存进行初始化
				double	*ATP = new	double[5 * T]();		//A的转置乘以P;
				double	*ATPA = new	double[5 * 5]();		//A的转置乘以P乘以A;
				double	*inv_ATPA = new	double[5 * 5]();		//(A的转置乘以P乘以A)的逆;
				double	*ATPL = new	double[5]();		//A的转置乘以P乘以L;
				double	*result = new	double[5]();		//(A的转置乘以P乘以A)乘以(A的转置乘以P乘以L)，(inv_ATPA)(ATPL);


				double	*AX = new	double[T]();		//A乘以X;
				double  *V = new	double[T]();		//V=AX-L
				double	*VT = new	double[1 * T]();
				double	*VTP = new	double[1 * T]();
				double	*VTPV = new	double[T * 1]();

				///////////////////////////////////////////列法方程;

				//cout<<"系数矩阵B和L"<<endl;																	//
				for (i = 0; i<MM_raim; i++)
				{
					ll[i] = (M2_gps_coor.X[i] - rcoor_raim.X) / M2_GPS_SR[i];
					mm[i] = (M2_gps_coor.Y[i] - rcoor_raim.Y) / M2_GPS_SR[i];
					nn[i] = (M2_gps_coor.Z[i] - rcoor_raim.Z) / M2_GPS_SR[i];
					A[i * 5 + 0] = ll[i];
					A[i * 5 + 1] = mm[i];
					A[i * 5 + 2] = nn[i];
					A[i * 5 + 3] = -1;
					//A[i*5+4]=0;								//初始化了就不需要了
					L[i] = M2_GPS_SR[i] - M2_gps_wj[i];

					//printf("%8.3f%8.3f%8.3f%8.3f%8.3f%16.3f\n",A[i*5+0],A[i*5+1],A[i*5+2],A[i*5+3],A[i*5+4],L[i]);	//

					P[i*T + i] = 1;									//给GPS定的权
				}
				for (j = MM_raim; j<T; j++)
				{
					ll[j] = (M2_bds_coor.X[j - MM_raim] - rcoor_raim.X) / M2_BDS_SR[j - MM_raim];
					mm[j] = (M2_bds_coor.Y[j - MM_raim] - rcoor_raim.Y) / M2_BDS_SR[j - MM_raim];
					nn[j] = (M2_bds_coor.Z[j - MM_raim] - rcoor_raim.Z) / M2_BDS_SR[j - MM_raim];
					A[j * 5 + 0] = ll[j];
					A[j * 5 + 1] = mm[j];
					A[j * 5 + 2] = nn[j];
					//A[j*5+3]=0;								//初始化了就不需要了;
					A[j * 5 + 4] = -1;
					L[j] = M2_BDS_SR[j - MM_raim] - M2_bds_wj[j - MM_raim];

					//printf("%8.3f%8.3f%8.3f%8.3f%8.3f%16.3f\n",A[j*5+0],A[j*5+1],A[j*5+2],A[j*5+3],A[j*5+4],L[j]);	//

					P[j*T + j] = 1;									//给BDS定的权
				}

				///////////////////////////////////////////通过函数的指针进行矩阵的运算，传出需要的矩阵;
				M_Tra(T, 5, A, AT);							//矩阵转置	A的转置		传出AT;
				M_Mul(5, T, T, AT, P, ATP);						//矩阵相乘	AT乘P		传出ATP;
				M_Mul(5, T, 5, ATP, A, ATPA);					//			ATP乘A		传出ATPA;
				M_Inv(5, ATPA, inv_ATPA);						//矩阵求逆	ATPA的逆		传出inv_ATPA;
				M_Mul(5, T, 1, ATP, L, ATPL);					//			ATP乘L		传出ATPL;
				M_Mul(5, 5, 1, inv_ATPA, ATPL, result);			//			inv_ATPA乘ATPL传出result;

				//cout<<inv_ATPA[1]<<inv_ATPA[2]<<inv_ATPA[3]<<inv_ATPA[4]<<inv_ATPA[5]<<endl;
				//cout<<ATPL[1]<<ATPL[2]<<ATPL[3]<<ATPL[4]<<ATPL[5]<<endl;
				if (inv_ATPA != NULL)
				{
					rcoor_raim.X = result[0];
					rcoor_raim.Y = result[1];
					rcoor_raim.Z = result[2];
					rcoor_raim.P1 = result[3];
					rcoor_raim.P2 = result[4];

					for (i = 0; i<5; i++)
						GDOP_raim += inv_ATPA[i * 5 + i];
					sate_num[IWGD].GDOP_raim = sqrt(GDOP_raim);
					for (i = 0; i<3; i++)
						PDOP_raim += inv_ATPA[i * 5 + i];
					sate_num[IWGD].PDOP_raim = sqrt(PDOP_raim);
				}
				else
				{
					rcoor_raim.X = 0;
					rcoor_raim.Y = 0;
					rcoor_raim.Z = 0;
					rcoor_raim.P1 = 0;
					rcoor_raim.P2 = 0;
					//printf("这个历元数据无法求解!\n");
					//system("pause");
				}

				double X[5][1];
				X[0][0] = rcoor_raim.X;
				X[0][1] = rcoor_raim.Y;
				X[0][2] = rcoor_raim.Z;
				X[0][3] = rcoor_raim.P1;
				X[0][4] = rcoor_raim.P2;
				//double	*AX=	new	double[T]();			//A乘以X;
				M_Mul(T, 5, 1, A, X[0], AX);							//矩阵相乘;
				//double  *V=		new	double[T]();			//V=AX-L

				for (int p = 0; p<T; p++)
				{
					V[p] = AX[p] - L[p];
				}
				//double *VT=		new	double[1*T]();
				//double *VTP=	new	double[1*T]();
				//double *VTPV=	new	double[T*1]();

				M_Tra(T, 1, V, VT);								//矩阵转置	A的转置		传出AT;
				M_Mul(1, T, T, VT, P, VTP);							//矩阵相乘	AT乘P		传出ATP;
				M_Mul(1, T, 1, VTP, V, VTPV);
				double RMS_raim = sqrt(*VTPV / (T - 5));
				double w[32];
				for (i = 0; i<T; i++)
				{
					w[i] = fabs(V[i]) / (RMS_raim*sqrt((T - 1.0) / T));
					//printf("%16.8f\n",w[i]);				//
				}
				double w1=0.0;int n_s=0;
				for(i=0;i<T;i++)
				{
					if(w[i]> w1)
					{
						w1=w[i];
						n_s=i;
					}
				}

				int NNN,PPP;
				NNN = MM_raim;
				PPP = KK_raim;
				//index = 1;				//说明有问题，要回代;



				if (n_s>NNN - 1)			//说明是BDS卫星的
				{
					bad_BPRN[chaoxian_num] = M2_BPRN[n_s - NNN];//如果GPS7颗，BDS9颗，现在pp=8，也就是w中第9个，那么就是BDS卫星的第2个对应于1，即8-7=1;
					for (int m=0;m<VBPC[IWGD].C_num;m++)//从0开始依次比对prn,IWGD的VBPC,注意20150807!!!!!;
					{
						if (bad_BPRN[chaoxian_num]==VBPC[IWGD].C_PRN[m])//当prn相同时就消除这颗卫星对应的内容;
						{
							for (int s1 = m; s1<VBPC[IWGD].C_num; s1++)//从坏星开始将后一个星内容覆盖前一个卫星内容;
							{
								/*M2_bds_coor.X[s - NNN] = M2_bds_coor.X[s - NNN + 1];
								M2_bds_coor.Y[s - NNN] = M2_bds_coor.Y[s - NNN + 1];
								M2_bds_coor.Z[s - NNN] = M2_bds_coor.Z[s - NNN + 1];
								M2_BDS_SR[s - NNN] = M2_BDS_SR[s - NNN + 1];
								M2_bds_wj[s - NNN] = M2_bds_wj[s - NNN + 1];
								BBPC[j].C_PRN[s - NNN]=BBPC[j].C_PRN[s - NNN+1];
								BBPC[j].CPC[s - NNN]=BBPC[j].CPC[s - NNN+1];*/
								VBPC[IWGD].C_PRN[s1]=VBPC[IWGD].C_PRN[s1+1];
								VBPC[IWGD].CPC[s1]=VBPC[IWGD].CPC[s1+1];
							}
							VBPC[IWGD].C_num--;
							break;
						}
					}

					B_bad_num++;
					KK_raim = PPP - 1;		//新的BDS卫星个数
					chaoxian_num++;
				}
				else					//说明是GPS卫星的
				{
					bad_GPRN[chaoxian_num] = M2_GPRN[n_s];
					for (int m=0;m<VBPC[IWGD].G_num;m++)//从0开始依次比对prn,IWGD的VBPC,注意20150807!!!!!;
					{
						if (bad_GPRN[chaoxian_num]==VBPC[IWGD].G_PRN[m])//当prn相同时就消除这颗卫星对应的内容;
						{
							for (int s = m; s<VBPC[IWGD].G_num; s++)//从坏星开始将后一个星内容覆盖前一个卫星内容;
							{
								/*M2_bds_coor.X[s - NNN] = M2_bds_coor.X[s - NNN + 1];
								M2_bds_coor.Y[s - NNN] = M2_bds_coor.Y[s - NNN + 1];
								M2_bds_coor.Z[s - NNN] = M2_bds_coor.Z[s - NNN + 1];
								M2_BDS_SR[s - NNN] = M2_BDS_SR[s - NNN + 1];
								M2_bds_wj[s - NNN] = M2_bds_wj[s - NNN + 1];
								BBPC[j].C_PRN[s - NNN]=BBPC[j].C_PRN[s - NNN+1];
								BBPC[j].CPC[s - NNN]=BBPC[j].CPC[s - NNN+1];*/
								VBPC[IWGD].G_PRN[s]=VBPC[IWGD].G_PRN[s+1];
								VBPC[IWGD].GPC[s]=VBPC[IWGD].GPC[s+1];
							}
							VBPC[IWGD].G_num--;
							break;
						}
					}
					G_bad_num++;
					MM_raim = NNN - 1;		//新的GPS卫星个数
					chaoxian_num++;

				}

				KK2=KK_raim;MM2=MM_raim;

				NWDGNSS_MOVING_POS_MODULE(GridValue, ih0[GridValue.Monitor_BS_ID].xyz,VBPC, dg[1],geph,rcoor2,sate_num[IWGD]);
				if(rcoor2.X!=0)
				{
					xyztch[0]=rcoor2.X;xyztch[1]=rcoor2.Y;xyztch[2]=rcoor2.Z;
					XYZ2NEU(ih0[GridValue.Monitor_BS_ID].xyz,xyztch,NEUtch);//NEU4差分改正后xyz0相对于真值的NEU，用于评定精度
				}
				else
				{
					NEUtch[0]=0;
					NEUtch[1]=0;
					NEUtch[2]=0;
					/*memset(Bn,0x00,sizeof(int)*20);
					memset(Bp,0x00,sizeof(int)*20);*/
					//memset(VBPC,0x00,sizeof(VBS_PR_CR)*30);//VBS_PR_CR)*200很重要20150805;
					VBPC[IWGD].G_num=0;
					VBPC[IWGD].C_num=0;
					break;
				}

				a=fabs(NEUtch[0]);
				b=fabs(NEUtch[1]);
				c=fabs(NEUtch[2]);
			}while(a>2.0||b>2.0||c>4.0);//N,E,U限差224m，经过半天采集应设为112m
		}
	}
	/*if (rcoor2.X != 0 && MM2 != 0 && KK2 != 0)
	{
	sate_num[igc].KK2 = KK2;
	sate_num[igc].MM2 = MM2;
	sate_num[igc].ALL_GB2 = ALL_GB2;
	sate_num[igc].delX2 = rcoor2.X;
	sate_num[igc].delY2 = rcoor2.Y;
	sate_num[igc].delZ2 = rcoor2.Z;
	sate_num[igc].M2_P1 = rcoor2.P1;
	sate_num[igc].M2_P2 = rcoor2.P2;
	sate_num[igc].GDOP2 = GDOP2;
	sate_num[igc].PDOP2 = PDOP2;
	}*/
}
void CNDGNSS::time2epoch(gtime_t t, double *ep)
{
    const int mday[]={ /* # of days in a month */
        31,28,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31,
        31,29,31,30,31,30,31,31,30,31,30,31,31,28,31,30,31,30,31,31,30,31,30,31
    };
    int days,sec,mon,day;
    
    /* leap year if year%4==0 in 1901-2099 */
    days=(int)(t.time/86400);
    sec=(int)(t.time-(time_t)days*86400);
    for (day=days%1461,mon=0;mon<48;mon++) {
        if (day>=mday[mon]) day-=mday[mon]; else break;
    }
    ep[0]=1970+days/1461*4+mon/12; ep[1]=mon%12+1; ep[2]=day+1;
    ep[3]=sec/3600; ep[4]=sec%3600/60; ep[5]=sec%60+t.sec;
}
/* gps time to time ------------------------------------------------------------
* convert week and tow in gps time to gtime_t struct
* args   : int    week      I   week number in gps time
*          double sec       I   time of week in gps time (s)
* return : gtime_t struct
*-----------------------------------------------------------------------------*/
gtime_t CNDGNSS::gpst2time(int week, double sec)
{
    gtime_t t=epoch2time(gpst0);
    
    if (sec<-1E9||1E9<sec) sec=0.0;
    t.time+=86400*7*week+(int)sec;
    t.sec=sec-(int)sec;
    return t;
}
gtime_t CNDGNSS::epoch2time(const double *ep)
{
    const int doy[]={1,32,60,91,121,152,182,213,244,274,305,335};
    gtime_t time={0};
    int days,sec,year=(int)ep[0],mon=(int)ep[1],day=(int)ep[2];
    
    if (year<1970||2099<year||mon<1||12<mon) return time;
    
    /* leap year if year%4==0 in 1901-2099 */
    days=(year-1970)*365+(year-1969)/4+doy[mon-1]+day-2+(year%4==0&&mon>=3?1:0);
    sec=(int)floor(ep[5]);
    time.time=(time_t)days*86400+(int)ep[3]*3600+(int)ep[4]*60+sec;
    time.sec=ep[5]-sec;
    return time;
}
/* time to gps time ------------------------------------------------------------
* convert gtime_t struct to week and tow in gps time
* args   : gtime_t t        I   gtime_t struct
*          int    *week     IO  week number in gps time (NULL: no output)
* return : time of week in gps time (s)
*-----------------------------------------------------------------------------*/
double CNDGNSS::time2gpst(gtime_t t, int *week)
{
    gtime_t t0=epoch2time(gpst0);
    time_t sec=t.time-t0.time;
    int w=(int)(sec/(86400*7));
    
    if (week) *week=w;
    return (double)(sec-w*86400*7)+t.sec;
}
void CNDGNSS::Kick_Unavailable_Station(GridAttribute &GridValue,int monitor_BSdg[],int NO_JZZUSED)
{

	for(int h = 1; h <= NO_JZZUSED; h++)
	{
		if(monitor_BSdg[h]==0)//说明h站没有数据，剔除
		{
			for(int jzz = 0 ; jzz < GridValue.BS_Num ; jzz++)
			{
				if(GridValue.BS_ID[jzz]==h)
				{
					if(GridValue.Monitor_BS_ID==h)
					{
						GridValue.Monitor_BS_ID=0;
					}
					else {}
					for(int zz = jzz ; zz < GridValue.BS_Num ; zz++)
					{
						GridValue.BS_ID[zz]=GridValue.BS_ID[zz+1];
						GridValue.DistanceOfGB[zz]=GridValue.DistanceOfGB[zz+1];
						GridValue.Reciprocal_DistanceOfGB[zz]=GridValue.Reciprocal_DistanceOfGB[zz+1];
					}
					GridValue.BS_Num=GridValue.BS_Num-1;
					jzz=jzz-1;
				}
				else {}
			}
		}
		else{};
	}
}

GPST CNDGNSS::Match_Epoch_Time(GridAttribute GridValue,BS_PR_CR_JH Save_BBPC[])
{
	GPST BST;
	memset(&BST,0x00,sizeof(BST));

	int Tmatch[StationNum_USED+1];
	memset(Tmatch,0,sizeof(Tmatch));
	for(int jzz = 0 ; jzz < GridValue.BS_Num ; jzz++)//便利每一时刻相同的占多少
	{
		int h=GridValue.BS_ID[jzz];
		if(h!=0&&fabs((double)h)<=StationNum_USED)
		{
			for(int jj = 0 ; jj < GridValue.BS_Num ; jj++)
			{
				int hh=GridValue.BS_ID[jj];
				if(hh!=0&&fabs((double)hh)<=StationNum_USED)
				{
					if(fabs(Save_BBPC[h].tg.second-Save_BBPC[hh].tg.second)<0.01 && int(Save_BBPC[h].tg.second)!=0 && int(Save_BBPC[hh].tg.second)!=0)
					{
						Tmatch[h]++;
					}
					else{}
				}
				else {};
			}
		}
		else{}
	}
	//for(int jzz = 0 ; jzz < GridValue[4].BS_Num ; jzz++)
	//{
	//	int h=GridValue[4].BS_ID[jzz];
	//	if(h!=0)
	//	{
	//		TRACE("%2d,",Tmatch[h]);
	//	}
	//}
	int Tmatch_max=-1;
	for(int jzz = 0 ; jzz < GridValue.BS_Num ; jzz++)//找出相同时刻最多的历元
	{
		int h=GridValue.BS_ID[jzz];
		if(h!=0&&fabs((double)h)<=StationNum_USED)
		{
			if(Tmatch_max==-1)
			{
				Tmatch_max=Tmatch[h];
				BST=Save_BBPC[h].tg;
			}
			else if(Tmatch_max<Tmatch[h])
			{
				Tmatch_max=Tmatch[h];
				BST=Save_BBPC[h].tg;
			}
			else if(Tmatch_max==Tmatch[h])
			{
				if(int(BST.second)<int(Save_BBPC[h].tg.second))
				{
					Tmatch_max=Tmatch[h];
					BST=Save_BBPC[h].tg;
				}
				else{}
			}
			else{}
		}
		else{}
	}

	//TRACE("BST=%8.1f\n",BST[4]);
	return BST;
}

int CNDGNSS::Kick_Delay_Station(GridAttribute &GridValue,BS_PR_CR_JH Save_BBPC[],GPST BST)
{
	int bst_index[StationNum_USED+1];
	memset(bst_index,0,sizeof(bst_index));
	int bst_index_sum;
	memset(&bst_index_sum,0,sizeof(bst_index_sum));
	for(int jzz = 0 ; jzz < GridValue.BS_Num ; jzz++)//剔除延迟的站
	{
		int h=GridValue.BS_ID[jzz];//格网中存在的基站站ID
		if(h!=0&&fabs((double)h)<=StationNum_USED)//遍历存在数据的站
		{
			if(fabs(BST.second-Save_BBPC[h].tg.second)<0.01)
			{
				bst_index[h]=1;//发现相同时刻，赋值为1
				bst_index_sum=bst_index_sum+bst_index[h];//累加
			}
			else 
			{
				if(GridValue.Monitor_BS_ID==h)
				{
					GridValue.Monitor_BS_ID=0;
				}
				else{}
				for(int zz = jzz ; zz < GridValue.BS_Num ; zz++)
				{
					GridValue.BS_ID[zz]=GridValue.BS_ID[zz+1];
					GridValue.DistanceOfGB[zz]=GridValue.DistanceOfGB[zz+1];
					GridValue.Reciprocal_DistanceOfGB[zz]=GridValue.Reciprocal_DistanceOfGB[zz+1];
				}
				GridValue.BS_Num=GridValue.BS_Num-1;
				jzz=jzz-1;
			}
		}
		else{};
	}
	return bst_index_sum;
}
double CNDGNSS::Confirm_First_Epoch(int stan,DATG dg[])
{
	double BST;
	memset(&BST,0x00,sizeof(BST));

	int Tmatch[30];
	memset(Tmatch,0,sizeof(Tmatch));
	for(int h = 1; h <= stan-1; h++)//便利每一时刻相同的占多少
	{
		if(dg[h].tg.second!=0.0)
		{
			for(int hh = 0 ; hh <= stan-1 ; hh++)
			{
				if(dg[hh].tg.second!=0.0)
				{
					if(fabs(dg[h].tg.second-dg[hh].tg.second)<0.01 && dg[h].tg.second!=0.0 && dg[hh].tg.second!=0.0)
					{
						Tmatch[h]++;
					}
				}
				else{}
			}
		}
		else{}
	}

	int Tmatch_max=-1;
	for(int h = 0 ; h <= stan-1 ; h++)//找出相同时刻最多的历元
	{
		if(dg[h].tg.second!=0.0)
		{
			if(Tmatch_max==-1)
			{
				Tmatch_max=Tmatch[h];
				BST=dg[h].tg.second;
			}
			else if(Tmatch_max<=Tmatch[h])
			{
				Tmatch_max=Tmatch[h];
				BST=dg[h].tg.second;
			}
			else{}
		}
		else{}
	}

	//TRACE("BST=%8.1f\n",BST[4]);
	return BST;
}



//glonass卫星位置计算

/* time difference -------------------------------------------------------------
* difference between gtime_t structs
* args   : gtime_t t1,t2    I   gtime_t structs
* return : time difference (t1-t2) (s)
*-----------------------------------------------------------------------------*/
double CNDGNSS::timediff(gtime_t t1, gtime_t t2)
{
    return difftime(t1.time,t2.time)+t1.sec-t2.sec;
}
/* add time --------------------------------------------------------------------
* add time to gtime_t struct
* args   : gtime_t t        I   gtime_t struct
*          double sec       I   time to add (s)
* return : gtime_t struct (t+sec)
*-----------------------------------------------------------------------------*/
gtime_t CNDGNSS::timeadd(gtime_t t, double sec)
{
    double tt;
    
    t.sec+=sec; tt=floor(t.sec); t.time+=(int)tt; t.sec-=tt;
    return t;
}
/* glonass orbit differential equations --------------------------------------*/
void CNDGNSS::deq(const double x[], double xdot[], const double acc[])
{
    double a,b,c,r2=dot(x,x,3),r3=r2*sqrt(r2),omg2=SQR(OMGE_GLO);
    
    if (r2<=0.0) {
        xdot[0]=xdot[1]=xdot[2]=xdot[3]=xdot[4]=xdot[5]=0.0;
        return;
    }
    /* ref [2] A.3.1.2 with bug fix for xdot[4],xdot[5] */
    a=1.5*J2_GLO*MU_GLO*SQR(RE_GLO)/r2/r3; /* 3/2*J2*mu*Ae^2/r^5 */
    b=5.0*x[2]*x[2]/r2;                    /* 5*z^2/r^2 */
    c=-MU_GLO/r3-a*(1.0-b);                /* -mu/r^3-a(1-b) */
    xdot[0]=x[3]; xdot[1]=x[4]; xdot[2]=x[5];
    xdot[3]=(c+omg2)*x[0]+2.0*OMGE_GLO*x[4]+acc[0];
    xdot[4]=(c+omg2)*x[1]-2.0*OMGE_GLO*x[3]+acc[1];
    xdot[5]=(c-2.0*a)*x[2]+acc[2];
}
/* glonass position and velocity by numerical integration --------------------*/
void CNDGNSS::glorbit(double t, double x[], const double acc[])
{
    double k1[6],k2[6],k3[6],k4[6],w[6];
    int i;
    
    deq(x,k1,acc); for (i=0;i<6;i++) w[i]=x[i]+k1[i]*t/2.0;
    deq(w,k2,acc); for (i=0;i<6;i++) w[i]=x[i]+k2[i]*t/2.0;
    deq(w,k3,acc); for (i=0;i<6;i++) w[i]=x[i]+k3[i]*t;
    deq(w,k4,acc);
    for (i=0;i<6;i++) x[i]+=(k1[i]+2.0*k2[i]+2.0*k3[i]+k4[i])*t/6.0;
}
/* glonass ephemeris to satellite clock bias -----------------------------------
* compute satellite clock bias with glonass ephemeris
* args   : gtime_t time     I   time by satellite clock (gpst)
*          geph_t *geph     I   glonass ephemeris
* return : satellite clock bias (s)
* notes  : see ref [2]
*-----------------------------------------------------------------------------*/
double CNDGNSS::geph2clk(gtime_t time, GEPH geph[],int glo_prn)
{
    double t;
    int i;
    
    //trace(4,"geph2clk: time=%s sat=%2d\n",time_str(time,3),geph->sat);
    gtime_t toe;
	memset(&toe,0x00,sizeof(gtime_t));
	toe.time = geph[glo_prn].a[0];
	toe.sec = geph[glo_prn].a[1];
    t=timediff(time,toe);
    
    for (i=0;i<2;i++) {
        t-=-geph[glo_prn].a[2]+geph[glo_prn].a[3]*t;//taun,gamn
    }
    return -geph[glo_prn].a[2]+geph[glo_prn].a[3]*t;
}
/* glonass ephemeris to satellite position and clock bias ----------------------
* compute satellite position and clock bias with glonass ephemeris
* args   : gtime_t time     I   time (gpst)
*          geph_t *geph     I   glonass ephemeris
*          double *rs       O   satellite position {x,y,z} (ecef) (m)
*          double *dts      O   satellite clock bias (s)
*          double *var      O   satellite position and clock variance (m^2)
* return : none
* notes  : see ref [2]
*-----------------------------------------------------------------------------*/
void CNDGNSS::geph2pos(gtime_t time, GEPH geph[], int glo_prn,double rs[], double dts[],
                     double *var)
{
    double t,tt,x[6];
    int i;
    
    //trace(4,"geph2pos: time=%s sat=%2d\n",time_str(time,3),geph->sat);
    gtime_t toe;
	memset(&toe,0x00,sizeof(gtime_t));
	toe.time = geph[glo_prn].a[0];
	toe.sec = geph[glo_prn].a[1];
    t=timediff(time,toe);
    
    dts[0]=-geph[glo_prn].a[2]+geph[glo_prn].a[3]*t;
    
    x[0]=geph[glo_prn].a[5];//posx
	x[1]=geph[glo_prn].a[9];//posy
	x[2]=geph[glo_prn].a[13];//posz
    x[3]=geph[glo_prn].a[6];//velx
	x[4]=geph[glo_prn].a[10];//vely
	x[5]=geph[glo_prn].a[14];//velz
 
    for (tt=t<0.0?-TSTEP:TSTEP;fabs(t)>1E-9;t-=tt) {
        if (fabs(t)<TSTEP) tt=t;
		double gloacc[3];
		memset(gloacc,0x00,sizeof(gloacc));
		gloacc[0]=geph[glo_prn].a[7];//accx
		gloacc[1]=geph[glo_prn].a[11];//accy
		gloacc[2]=geph[glo_prn].a[15];//accz
        glorbit(tt,x,gloacc);
    }
    for (i=0;i<3;i++) rs[i]=x[i];
    
    *var=SQR(ERREPH_GLO);
}
//创建日志文件的名称
void CNDGNSS::GenerateLogName()
{
    time_t curTime;
	struct tm pTimeInfo = {0};
	errno_t err;
    time(&curTime);
    localtime_s(&pTimeInfo,&curTime);
    char temp[1024] = {0};
    //日志的名称如：2013-01-01.log
	sprintf_s(temp,sizeof(temp), "LogFile%04d%02d%02d%02d.log", pTimeInfo.tm_year+1900, pTimeInfo.tm_mon + 1, pTimeInfo.tm_mday,pTimeInfo.tm_hour);
    if(0 != strcmp(m_strCurLogName, temp))
    {
        strcpy_s(m_strCurLogName,sizeof(m_strCurLogName),temp);
        if(m_pFileStream)
            fclose(m_pFileStream);
        char temp[1024] = {0};
        //strcat_s(temp,sizeof(temp), m_strLogPath);
        strcat_s(temp,sizeof(temp), m_strCurLogName);
        //以追加的方式打开文件流
        //err = fopen_s(&m_pFileStream,temp, "ab");
		
		if ((m_pFileStream = _fsopen(temp, "ab", _SH_DENYNO)) != NULL)
		{
			fseek(m_pFileStream, 0, SEEK_END);
		}
    }
}
//写一般信息
void CNDGNSS::TraceInfo(const char * strInfo, ...)
{
    //判断当前的写日志级别，若设置只写错误和警告信息则函数返回
    //if(m_nLogLevel >= EnumLogLevel::LogLevelMid)
    //    return;
    if(!strInfo)
        return;
    char pTemp[1024] = {0};
	CString strtemp;
	CTime ct = CTime::GetCurrentTime();
	strtemp.Format(_T("%04d/%02d/%02d-%02d:%02d:%02d :"),ct.GetYear(),ct.GetMonth(),ct.GetDay(),ct.GetHour(),ct.GetMinute(),ct.GetSecond());

    va_list arg_ptr = NULL;
    va_start(arg_ptr, strInfo);
    vsprintf_s(pTemp, sizeof(pTemp),strInfo, arg_ptr);
    va_end(arg_ptr);

	CString strmsg;
	strmsg.Format(_T("%s"),pTemp);

	fprintf(m_pFileStream,_T("%s%s%s\n"),strtemp,INFOPREFIX,strmsg);

    arg_ptr = NULL;
}
//写警告信息
void CNDGNSS::TraceWarn(const char * strInfo, ...)
{
    //判断当前的写日志级别，若设置只写错误和警告信息则函数返回
    //if(m_nLogLevel >= EnumLogLevel::LogLevelMid)
    //    return;
    if(!strInfo)
        return;
    char pTemp[1024] = {0};
	CString strtemp;
	CTime ct = CTime::GetCurrentTime();
	strtemp.Format(_T("%04d/%02d/%02d-%02d:%02d:%02d :"),ct.GetYear(),ct.GetMonth(),ct.GetDay(),ct.GetHour(),ct.GetMinute(),ct.GetSecond());

    va_list arg_ptr = NULL;
    va_start(arg_ptr, strInfo);
    vsprintf_s(pTemp, sizeof(pTemp),strInfo, arg_ptr);
    va_end(arg_ptr);

	CString strmsg;
	strmsg.Format(_T("%s"),pTemp);

	fprintf(m_pFileStream,_T("%s%s%s\n"),strtemp,WARNINGPREFIX,strmsg);

    arg_ptr = NULL;
}
//写错误信息
void CNDGNSS::TraceError(const char * strInfo, ...)
{
    //判断当前的写日志级别，若设置只写错误和警告信息则函数返回
    //if(m_nLogLevel >= EnumLogLevel::LogLevelMid)
    //    return;
    if(!strInfo)
        return;
    char pTemp[1024] = {0};
	CString strtemp;
	CTime ct = CTime::GetCurrentTime();
	strtemp.Format(_T("%04d/%02d/%02d-%02d:%02d:%02d :"),ct.GetYear(),ct.GetMonth(),ct.GetDay(),ct.GetHour(),ct.GetMinute(),ct.GetSecond());

    va_list arg_ptr = NULL;
    va_start(arg_ptr, strInfo);
    vsprintf_s(pTemp, sizeof(pTemp),strInfo, arg_ptr);
    va_end(arg_ptr);

	CString strmsg;
	strmsg.Format(_T("%s"),pTemp);

	fprintf(m_pFileStream,_T("%s%s%s\n"),strtemp,ERRORPREFIX,strmsg);

    arg_ptr = NULL;
}
//GPS/BDS/GLONASS
double CNDGNSS::Produce_Receiver_COOR_3SYS(DATG dg0,GEPH geph[],rp &rcoor0,double gsvxyz[][3],double bsvxyz[][3],double rsvxyz[][3],double &GDOP,int satn[])
{
	DATG dg2[1];
	IOFH ih2[1];
	memset(dg2,0x00,sizeof(dg2));
	memset(ih2,0x00,sizeof(ih2));
	memset(gsvxyz,0x00,sizeof(gsvxyz));
	memset(bsvxyz,0x00,sizeof(bsvxyz));
	memset(rsvxyz,0x00,sizeof(rsvxyz));
	memset(&GDOP,0x00,sizeof(GDOP));
	memset(satn,0,sizeof(satn));
	dg2[0] = dg0;
	//ih2[0] = ih0;
	int G_num,C_num,R_num;

	GPST T_BBPC={0};
	T_BBPC=dg2[0].tg;

	sp		gps_coor,bds_coor,glo_coor;			//卫星坐标_结构体
	memset(&gps_coor,0x00,sizeof(gps_coor));
	memset(&bds_coor,0x00,sizeof(bds_coor));
	memset(&glo_coor,0x00,sizeof(glo_coor));
	double	PDOP=0.0,RMS=0.0,X0=0.0,Y0=0.0,Z0=0.0,delt=0.0;
	int final_N=0,final_P=0,jinxingcuchatichu=0,xhyz=0,out_biaozhi=0;	
	memset(&rcoor0,0x00,sizeof(rcoor0));

	rcoor0.X=0.0;
	rcoor0.Y=0.0;
	rcoor0.Z=0.0;
	do 
	{
		if(xhyz>20) break;//最多循环10次，退出
		delt=0.0;													//计算位置坐标，循环置0;
		G_num=0;
		C_num=0;
		R_num=0;
		satn[0]=0;
		satn[1]=0;
		satn[2]=0;
		int		g_PRN[32]={0},b_PRN[32]={0},r_PRN[32]={0};
		double gps_wj_end[32]={0},GPS_SR_end[32]={0};
		double bds_wj_end[32]={0},BDS_SR_end[32]={0};
		double glo_wj_end[32]={0},GLO_SR_end[32]={0};
		double	G_XK=0,G_YK=0,G_ZK=0,	B_XK=0,B_YK=0,B_ZK=0,	R_XK=0,R_YK=0,R_ZK=0;
		int		NN=0,PP=0,QQ=0;										//可利用GPS，BDS，GLONASS卫星数，这里再一次定义是为了将其输出;
		int		totle_sat=0;
		X0=rcoor0.X;//初值为0
		Y0=rcoor0.Y;
		Z0=rcoor0.Z;
		//X0=0.0;
		//Y0=0.0;
		//Z0=0.0;
		for (int jj = 0; jj < dg2[0].nsat; jj++)
		{
			//if (dg2[0].prn[jj] >= 1 &&dg2[0].prn[jj] < 33)
			//{
			//	double g_swj = 0, g_R = 0;
			//	G_XK = 0, G_YK = 0, G_ZK = 0;
			//	int prn_satellite = dg2[0].prn[jj];
			//	if (geph[prn_satellite].a[24] == 1)//卫星不健康
			//		continue;
			//	double svclk=GetSVpos(dg2[0].tg.week,dg2[0].tg.second,geph[prn_satellite].a,X0,Y0,Z0,&G_XK, &G_YK, &G_ZK); 
			//	if(svclk > 10.0)
			//		continue;
			//	g_R=sqrt(pow(G_XK-X0,2)+pow(G_YK-Y0,2)+pow(G_ZK-Z0,2));//卫地距
			//	double rs[3]={0.0},rr[3]={0.0},r2suv[3]={0},pos[3]={0},azel[2]={0};
			//	double EL = 0;
			//	rs[0]=G_XK;
			//	rs[1]=G_YK;
			//	rs[2]=G_ZK;
			//	rr[0]=X0;
			//	rr[1]=Y0;
			//	rr[2]=Z0;
			//	geodist(rs,rr,r2suv);
			//	ecef2pos(rr,pos);
			//	EL=satazel(pos,r2suv,azel);
			//	if(fabs(EL*R2D)>10.0)//判断卫星高度角
			//	{
			//		g_swj = dg2[0].data[jj][0] + svclk*299792458.0 ;//伪距
			//	}
			//	else							//高度角为10度((PI/18=0.17453292519943))，小于10的卫星舍去  15度 PI/12=0.2617993877991
			//	{
			//		g_R = 0;
			//		g_swj = 0;
			//		G_XK = 0;
			//		G_YK = 0;
			//		G_ZK = 0;
			//	}
			//	if (g_swj != 0 && g_R != 0)
			//	{
			//		gsvxyz[prn_satellite][0]=gps_coor.X[G_num]		=G_XK;                   //为求接收机钟差，保留卫星坐标，卫星伪距，卫地几何距离20150819;
			//		gsvxyz[prn_satellite][1]=gps_coor.Y[G_num]		=G_YK;
			//		gsvxyz[prn_satellite][2]=gps_coor.Z[G_num]		=G_ZK;
			//		gps_wj_end[G_num]       =g_swj;
			//		GPS_SR_end[G_num]		=g_R;
			//		g_PRN[G_num]		=dg2[0].prn[jj];
			//		G_num++;
			//		satn[1]++;
			//	}
			//}

			if (dg2[0].prn[jj] >= 1 &&dg2[0].prn[jj] < 33)//GPS
			{
				int GPSPRN=dg2[0].prn[jj];
				double g_swj = 0, g_R = 0;
				G_XK = 0, G_YK = 0, G_ZK = 0;
				GNSS_Position_Module(geph, dg2, 0,X0, Y0, Z0, &g_swj, &g_R, &G_XK, &G_YK, &G_ZK, jj, 1);//*****dg后面的参数为站号,Njz,(0,1,2,3,4……)为了配合dg【】中的号,最后一位整数1为GPS系统，2为BDS系统!!!!!!!!!!!!!;
				if (g_swj != 0 && g_R != 0)
				{
					gsvxyz[GPSPRN][0]=gps_coor.X[G_num]		=G_XK;                   //为求接收机钟差，保留卫星坐标，卫星伪距，卫地几何距离20150819;
					gsvxyz[GPSPRN][1]=gps_coor.Y[G_num]		=G_YK;
					gsvxyz[GPSPRN][2]=gps_coor.Z[G_num]		=G_ZK;
					gps_wj_end[G_num]     =g_swj;
					GPS_SR_end[G_num]		=g_R;
					g_PRN[G_num]		=dg2[0].prn[jj];
					G_num++;
					satn[1]++;
				}
			}

			if (dg2[0].prn[jj] >= 33 && dg2[0].prn[jj] < 57)//glonass，张静云版本，周万振加
			{
				//continue;
				double glo_swj = 0, glo_R = 0;
				R_XK = 0, R_YK = 0, R_ZK = 0;
				int prn_satellite = dg2[0].prn[jj];
				if (geph[prn_satellite].a[8] == 1)//卫星不健康
					continue;
				if (geph[prn_satellite].a[5] == 0.0||geph[prn_satellite].a[9] == 0.0||geph[prn_satellite].a[13] == 0.0)
					continue;
				double  tc=0,tc1=0;
				gtime_t glo_t;
				glo_t.time=geph[prn_satellite].a[0];
				glo_t.sec =geph[prn_satellite].a[1];
				gtime_t glo_ot = gpst2time(dg2[0].tg.week, dg2[0].tg.second);
				double svclk=GetSVpos_GLO(glo_t,glo_ot,dg2[0].data[jj][0],geph[prn_satellite].a,X0,Y0,Z0,&R_XK, &R_YK, &R_ZK,tc);
				if(svclk > 10.0)
					continue;
				glo_R=sqrt(pow(R_XK-X0,2)+pow(R_YK-Y0,2)+pow(R_ZK-Z0,2));//卫地距
				double rs[3]={0.0},rr[3]={0.0},r2suv[3]={0},pos[3]={0},azel[2]={0};
				double EL = 0;
				rs[0]=R_XK;
				rs[1]=R_YK;
				rs[2]=R_ZK;
				rr[0]=X0;
				rr[1]=Y0;
				rr[2]=Z0;
				geodist(rs,rr,r2suv);
				ecef2pos(rr,pos);
				EL=satazel(pos,r2suv,azel);
				if(fabs(EL*R2D)>10.0)//判断卫星高度角
				{
					glo_swj = dg2[0].data[jj][0] + svclk*299792458.0 ;//伪距
				}
				else							//高度角为10度((PI/18=0.17453292519943))，小于10的卫星舍去  15度 PI/12=0.2617993877991
				{
					glo_R = 0;
					glo_swj = 0;
					R_XK = 0;
					R_YK = 0;
					R_ZK = 0;
				}
				if (glo_swj != 0 && glo_R != 0)
				{
					rsvxyz[prn_satellite-32][0]=glo_coor.X[R_num]		=R_XK;                   //为求接收机钟差，保留卫星坐标，卫星伪距，卫地几何距离20150819;
					rsvxyz[prn_satellite-32][1]=glo_coor.Y[R_num]		=R_YK;
					rsvxyz[prn_satellite-32][2]=glo_coor.Z[R_num]		=R_ZK;
					glo_wj_end[R_num]     =glo_swj;
					GLO_SR_end[R_num]		=glo_R;
					r_PRN[R_num]		=dg2[0].prn[jj];
					R_num++;
					satn[2]++;
				}
			}

			//if (dg2[0].prn[jj] >= 33 && dg2[0].prn[jj] < 57)//glonass，160815，周万振
			//{
			//	double glo_swj = 0, glo_R = 0;
			//	double rs[6];
			//	memset(rs,0x00,sizeof(rs));
			//	GLONASS_POS_MODULE(geph,dg2,0,X0,Y0,Z0,&glo_swj,&glo_R,rs,jj);//glonass
			//	if (glo_swj != 0 && glo_R != 0)
			//	{
			//		int GLOPRN=dg2[0].prn[jj]-32;
			//		rsvxyz[GLOPRN][0]=glo_coor.X[R_num]		=rs[0];                   //为求接收机钟差，保留卫星坐标，卫星伪距，卫地几何距离20150819;
			//		rsvxyz[GLOPRN][1]=glo_coor.Y[R_num]		=rs[1];
			//		rsvxyz[GLOPRN][2]=glo_coor.Z[R_num]		=rs[2];
			//		glo_wj_end[R_num]		=glo_swj;
			//		GLO_SR_end[R_num]		=glo_R;
			//		r_PRN[R_num]			=dg2[0].prn[jj];
			//		R_num++;
			//		satn[2]++;
			//	}
			//}

			//if (dg2[0].prn[jj] >= 161 && dg2[0].prn[jj] < 181)//BDS
			//{
			//	double b_swj = 0, b_R = 0;
			//	B_XK = 0, B_YK = 0, B_ZK = 0;
			//	int prn_satellite = dg2[0].prn[jj];
			//	if (geph[prn_satellite].a[24] == 1)//卫星不健康
			//		continue;
			//	double svclk=0.0;
			//	if(prn_satellite>165)
			//	{
			//		svclk=GetSVpos_BDS(dg2[0].tg.week,dg2[0].tg.second-14,geph[prn_satellite].a,X0,Y0,Z0,&B_XK,&B_YK, &B_ZK); 
			//		if(svclk > 10.0)
			//			continue;
			//	}
			//	else if(prn_satellite<=165)
			//	{
			//		svclk=GetSVpos_GEO(dg2[0].tg.week,dg2[0].tg.second-14,geph[prn_satellite].a,X0,Y0,Z0,&B_XK,&B_YK, &B_ZK);
			//		if(svclk > 10.0)
			//			continue;
			//	}
			//	b_R=sqrt(pow(B_XK-X0,2)+pow(B_YK-Y0,2)+pow(B_ZK-Z0,2));//卫地距
			//	double rs[3]={0.0},rr[3]={0.0},r2suv[3]={0},pos[3]={0},azel[2]={0};
			//	double EL = 0;
			//	rs[0]=B_XK;
			//	rs[1]=B_YK;
			//	rs[2]=B_ZK;
			//	rr[0]=X0;
			//	rr[1]=Y0;
			//	rr[2]=Z0;
			//	geodist(rs,rr,r2suv);
			//	ecef2pos(rr,pos);
			//	EL=satazel(pos,r2suv,azel);
			//	if(fabs(EL*R2D)>10.0)//判断卫星高度角
			//	{
			//		b_swj = dg2[0].data[jj][2] + svclk*299792458.0 ;//伪距
			//	}
			//	else							//高度角为10度((PI/18=0.17453292519943))，小于10的卫星舍去  15度 PI/12=0.2617993877991
			//	{
			//		b_R = 0;
			//		b_swj = 0;
			//		B_XK = 0;
			//		B_YK = 0;
			//		B_ZK = 0;
			//	}
			//	if (b_swj != 0 && b_R != 0)
			//	{
			//		bsvxyz[prn_satellite-160][0]=bds_coor.X[C_num]		=B_XK;                   //为求接收机钟差，保留卫星坐标，卫星伪距，卫地几何距离20150819;
			//		bsvxyz[prn_satellite-160][1]=bds_coor.Y[C_num]		=B_YK;
			//		bsvxyz[prn_satellite-160][2]=bds_coor.Z[C_num]		=B_ZK;
			//		bds_wj_end[C_num]       =b_swj;
			//		BDS_SR_end[C_num]		=b_R;
			//		b_PRN[C_num]		=dg2[0].prn[jj];
			//		C_num++;								//Bp[Njz]为可利用GPS卫星数目
			//		satn[0]++;
			//	}
			//}

			if (dg2[0].prn[jj] >= 161 && dg2[0].prn[jj] < 181)
			{
				int BDSPRN=dg2[0].prn[jj];
				double b_swj = 0, b_R = 0;
				B_XK = 0, B_YK = 0, B_ZK = 0;
				GNSS_Position_Module(geph, dg2, 0, X0, Y0, Z0, &b_swj, &b_R, &B_XK, &B_YK, &B_ZK, jj, 2);//dg后面的参数为站号,0,1,2,3,为了配合dg【】中的号，最后一位整数1为GPS系统，2为BDS系统;
				if (b_swj != 0 && b_R != 0)
				{
					bsvxyz[BDSPRN-160][0]=bds_coor.X[C_num]		=B_XK;                   //为求接收机钟差，保留卫星坐标，卫星伪距，卫地几何距离20150819;
					bsvxyz[BDSPRN-160][1]=bds_coor.Y[C_num]		=B_YK;
					bsvxyz[BDSPRN-160][2]=bds_coor.Z[C_num]		=B_ZK;
					bds_wj_end[C_num]     =b_swj;
					BDS_SR_end[C_num]		=b_R;
					b_PRN[C_num]		=dg2[0].prn[jj];
					C_num++;								//Bp[Njz]为可利用GPS卫星数目
					satn[0]++;
				}
			}
		}

		NN=G_num;
		PP=C_num;
		QQ=R_num;
		totle_sat=NN+PP+QQ;
		//NN=0;
		if(NN>0&&PP>0&&QQ>0&&totle_sat>6)	//3系统GPS/BDS/GLO,160815,周万振
		{
			gps_bds_glo_coor(&rcoor0,gps_coor,gps_wj_end,GPS_SR_end,bds_coor,bds_wj_end,BDS_SR_end,glo_coor,glo_wj_end,GLO_SR_end,totle_sat,NN,PP,QQ,&GDOP,&PDOP,T_BBPC.second);

			if(rcoor0.X==0&&rcoor0.Y==0&&rcoor0.Z==0)//不能循环太多，比如循环39次，这里的rcoor.X==0&&rcoor.Y==0&&rcoor.Z==0，但是是正确的
			{
				rcoor0.P1=0;
				rcoor0.P2=0;
				rcoor0.P3=0;
				break;
			}
			else
			{

				rcoor0.X=rcoor0.X+X0;	//新的接收机坐标=改正数+初值，下面判断，如果delt>0.001的话，返回do，将rcoor.X重新作为初值，循环计算到delt<0.001;
				rcoor0.Y=rcoor0.Y+Y0;
				rcoor0.Z=rcoor0.Z+Z0;
				delt=rcoor0.X-X0;
				out_biaozhi=1;

			}
		}
		else if(NN>0&&PP>0&&QQ==0&&totle_sat>5)	//2系统GPS/BDS，为了防止和星历相同时刻时，有单个系统的星为0时，无法解算，程序无法进行，大于5时，RMS才有值20150701,有单个系统的星为0时，可以解算;
		{
			recei_coor(&rcoor0,gps_coor,gps_wj_end,GPS_SR_end,bds_coor,bds_wj_end,BDS_SR_end,totle_sat,NN,PP,&GDOP,&PDOP,T_BBPC.second);//计算接收机坐标,返回位置的改正数rcoor.X、rcoor.Y、rcoor.Z;

			if(rcoor0.X==0&&rcoor0.Y==0&&rcoor0.Z==0)//不能循环太多，比如循环39次，这里的rcoor.X==0&&rcoor.Y==0&&rcoor.Z==0，但是是正确的
			{
				rcoor0.P1=0;
				rcoor0.P2=0;
				break;
			}
			else
			{

				rcoor0.X=rcoor0.X+X0;	//新的接收机坐标=改正数+初值，下面判断，如果delt>0.001的话，返回do，将rcoor.X重新作为初值，循环计算到delt<0.001;
				rcoor0.Y=rcoor0.Y+Y0;
				rcoor0.Z=rcoor0.Z+Z0;
				delt=rcoor0.X-X0;
				out_biaozhi=1;

			}
		}
		else if(NN>0&&PP==0&&QQ>0&&totle_sat>5)	//2系统GPS/GLO，为了防止和星历相同时刻时，有单个系统的星为0时，无法解算，程序无法进行，大于5时，RMS才有值20150701,有单个系统的星为0时，可以解算;
		{
			recei_coor(&rcoor0,gps_coor,gps_wj_end,GPS_SR_end,glo_coor,glo_wj_end,GLO_SR_end,totle_sat,NN,QQ,&GDOP,&PDOP,T_BBPC.second);//计算接收机坐标,返回位置的改正数rcoor.X、rcoor.Y、rcoor.Z;

			if(rcoor0.X==0&&rcoor0.Y==0&&rcoor0.Z==0)//不能循环太多，比如循环39次，这里的rcoor.X==0&&rcoor.Y==0&&rcoor.Z==0，但是是正确的
			{
				rcoor0.P1=0;
				rcoor0.P2=0;
				break;
			}
			else
			{

				rcoor0.X=rcoor0.X+X0;	//新的接收机坐标=改正数+初值，下面判断，如果delt>0.001的话，返回do，将rcoor.X重新作为初值，循环计算到delt<0.001;
				rcoor0.Y=rcoor0.Y+Y0;
				rcoor0.Z=rcoor0.Z+Z0;
				delt=rcoor0.X-X0;
				out_biaozhi=1;

			}
		}
		else if (NN>4&&QQ==0&&PP==0)//单系统，但只有GPS一种系统可用
		{
			spp_recei_coor_single(&rcoor0,gps_coor,gps_wj_end,&NN,GPS_SR_end,&GDOP,&PDOP);//计算接收机坐标,返回位置的改正数rcoor.X、rcoor.Y、rcoor.Z;
			if(rcoor0.X==0&&rcoor0.Y==0&&rcoor0.Z==0)//不能循环太多，比如循环39次，这里的rcoor.X==0&&rcoor.Y==0&&rcoor.Z==0，但是是正确的
			{
				break;
			}
			else
			{
				rcoor0.X=rcoor0.X+X0;	//新的接收机坐标=改正数+初值，下面判断，如果delt>0.001的话，返回do，将rcoor.X重新作为初值，循环计算到delt<0.001;
				rcoor0.Y=rcoor0.Y+Y0;
				rcoor0.Z=rcoor0.Z+Z0;
				delt=rcoor0.X-X0;
				rcoor0.P1=rcoor0.P;//单GPS系统钟差
				out_biaozhi=1;

			}
		}
		else if (NN==0&&QQ==0&&PP>4)//单系统，但只有BDS一种系统可用
		{
			spp_recei_coor_single(&rcoor0,bds_coor,bds_wj_end,&PP,BDS_SR_end,&GDOP,&PDOP);//计算接收机坐标,返回位置的改正数rcoor.X、rcoor.Y、rcoor.Z;
			if(rcoor0.X==0&&rcoor0.Y==0&&rcoor0.Z==0)//不能循环太多，比如循环39次，这里的rcoor.X==0&&rcoor.Y==0&&rcoor.Z==0，但是是正确的
			{
				break;
			}
			else
			{
				rcoor0.X=rcoor0.X+X0;	//新的接收机坐标=改正数+初值，下面判断，如果delt>0.001的话，返回do，将rcoor.X重新作为初值，循环计算到delt<0.001;
				rcoor0.Y=rcoor0.Y+Y0;
				rcoor0.Z=rcoor0.Z+Z0;
				delt=rcoor0.X-X0;
				rcoor0.P2=rcoor0.P;//单BDS系统钟差给
				out_biaozhi=1;

			}
		}
		else if (QQ>4&&PP==0&&NN==0)//单系统，但只有GLO一种系统,周万振
		{
			spp_recei_coor_single(&rcoor0,glo_coor,glo_wj_end,&QQ,GLO_SR_end,&GDOP,&PDOP);//计算接收机坐标,返回位置的改正数rcoor.X、rcoor.Y、rcoor.Z;
			if(rcoor0.X==0&&rcoor0.Y==0&&rcoor0.Z==0)//不能循环太多，比如循环39次，这里的rcoor.X==0&&rcoor.Y==0&&rcoor.Z==0，但是是正确的
			{
				break;
			}
			else
			{
				rcoor0.X=rcoor0.X+X0;	//新的接收机坐标=改正数+初值，下面判断，如果delt>0.001的话，返回do，将rcoor.X重新作为初值，循环计算到delt<0.001;
				rcoor0.Y=rcoor0.Y+Y0;
				rcoor0.Z=rcoor0.Z+Z0;
				delt=rcoor0.X-X0;
				rcoor0.P1=rcoor0.P;//单GLO系统钟差给P1;
				out_biaozhi=1;

			}
		}
		else 
			break;

		xhyz++;
	} while (fabs(delt)>0.0000001||rcoor0.X==0);
	return 0;
}
void CNDGNSS::GNSS_Position_Module(GEPH m_GEPHTemp[],DATG dg[],int sta_num,double &X0,double &Y0,double &Z0,double *swj,double *RR,double *XK,double *YK,double *ZK,int gnss_num,int GNSS_type)//GNSS_type：1代表GPS，2代表BDS

{
	double prange=0.0;
	double GPST_second;
	GPST_second=dg[sta_num].tg.second;
	if(GNSS_type==2)						//2代表BDS系统
		GPST_second-=14;
	double X=0,Y=0,Z=0;
	double transmit_t;

	double transmit_t0=0.07;				//令信号传输时间为0.07s
	double R=0;								//卫地距离;
	double C=299792458.0;
	double RECD;							//relativistic_effect_correction_distence相对论影响距离


	int prn_satellite = dg[sta_num].prn[gnss_num];
	if(GNSS_type==2)
	{
		prn_satellite=prn_satellite;
		prange=dg[sta_num].data[gnss_num][0];//需要注意
	}
	else if(GNSS_type==1)
	{
		prange=dg[sta_num].data[gnss_num][0];
	}
	if (m_GEPHTemp[prn_satellite].a[24] == 1)//卫星不健康
		return;

	double deltt = fabs(m_GEPHTemp[prn_satellite].a[11] - GPST_second); 

	//TRACE("prn=%c:%d deltt=%f\n", dg[sta_num].kind[gnss_num], prn_satellite, deltt);
	//	fprintf_s(m_fpche, "prn=%c:%d deltt=%f\n", dg[sta_num].kind[gnss_num], prn_satellite, deltt);


	if (GNSS_type == 1)//GPS
	{			
		if (deltt>7210)//toe时间过长，大于2h
			return;
	}
	if (GNSS_type == 2)//BDS
	{						
		if(deltt>3660)//toe时间过长，大于1h
			return;
	}
	do
	{
		transmit_t = transmit_t0;
		Produce_gnss_satellite_coor(m_GEPHTemp, gnss_num, dg, sta_num, GPST_second, transmit_t, &X, &Y, &Z, &RECD, GNSS_type);//计算卫星位置坐标;
		R = sqrt(pow(X - X0, 2) + pow(Y - Y0, 2) + pow(Z - Z0, 2));		//pow(底数，幂)，如3的平方pow(3，2);
		transmit_t0 = R / C;
	} while (fabs(transmit_t - transmit_t0)>10e-15);
	double we = 7.2921151467e-5;
	double det_alph = we*transmit_t0;			//transmit_t0信号传播时间

	double rs[3]={0},rr[3]={0},r2suv[3]={0},pos[3]={0},azel[2]={0};
	double EL = 0;
	rs[0]=*XK = X + Y * sin(det_alph);				//考虑地球自传改正后卫星在地固坐标系中坐标;
	rs[1]=*YK = -X * sin(det_alph) + Y;				//传出计算的卫星坐标;
	rs[2]=*ZK = Z;
	rr[0]=X0;
	rr[1]=Y0;
	rr[2]=Z0;
	*RR = sqrt(pow(*XK - X0, 2) + pow(*YK - Y0, 2) + pow(*ZK - Z0, 2));	//卫地距;

	geodist(rs,rr,r2suv);
	ecef2pos(rr,pos);
	EL=satazel(pos,r2suv,azel);


	//Produce_ion(swj, dg, sta_num, gnss_num, GNSS_type);	//伪距电离层改正;

	//double EL = 0, B = 0, L = 0, H = 0;
	//double dtrop;
	//				double PI=3.141592653589793;
	//choose_sat(*XK, *YK, *ZK, &EL, &B, &L, &H, X0, Y0, Z0);			//筛除卫星高度角小于规定值的卫星（比如小于10°）
	if (fabs(EL*R2D) >= 10 && prange!=0 /*&& dg[sta_num].data[gnss_num][2]>0 && fabs(dg[sta_num].data[gnss_num][0]-dg[sta_num].data[gnss_num][2])<20*/)						//设高度角为10度((PI/18=0.17453292519943))，小于10的卫星舍去  15度 PI/12=0.2617993877991
	{
		//trop_mod(&dtrop, H, EL);				//对流层模型改正（SAAS改进模型，内置了映射函数）
		double t_toe = GPST_second - transmit_t0 - m_GEPHTemp[prn_satellite].a[11];//非常注意啊：这点我之前一直弄错啦;直到20130309才发现
		double Ts = m_GEPHTemp[prn_satellite].a[0] + m_GEPHTemp[prn_satellite].a[1] * t_toe + m_GEPHTemp[prn_satellite].a[2] * t_toe*t_toe;//GPS卫星钟差
		double Ts_swj = Ts*C;
		//					*g_swj+=+Ts*C;
		//*swj=*swj+Ts_swj-dtrop+RECD;		//电离层，对流层，卫星钟差，相对论效应改正后的伪距;
		//					*g_swj=*g_swj+Ts*C-dtrop;
		//*swj = dg[sta_num].data[gnss_num][0] + RECD;
		*swj = prange + RECD + Ts*C ;
	}
	else									//高度角为10度((PI/18=0.17453292519943))，小于10的卫星舍去  15度 PI/12=0.2617993877991
	{
		*RR = 0;
		*swj = 0;
		*XK = 0;
		*YK = 0;
		*ZK = 0;
	}

}
int CNDGNSS::Produce_gnss_satellite_coor(GEPH m_GEPHTemp[],int jj,DATG dg[],int sta_num,double current_time,double transmit_t,double *Xk,double *Yk,double *Zk,double *RECD,int GNSS_type)
//current_time为接收机当前时间，通过指针从观测文件中传过来，已经改正到GPST下的秒，来计算的就是此刻的卫星位置
{

	int satprn=dg[sta_num].prn[jj];
	if(GNSS_type==2)
		satprn=satprn;
	double GM=3.9860047e14;
	double A=m_GEPHTemp[satprn].a[10]*m_GEPHTemp[satprn].a[10]; //长半轴;
	double n0=sqrt(GM/(A*A*A));							//平均角速度;

	double C=299792458.0;
	double tk=current_time-transmit_t-m_GEPHTemp[satprn].a[11];   //归化时间//current_time为接收机当前时间，已经改正到GPST下的秒
	if (tk>302400)
		tk=tk-604800;
	if (tk<-302400)
		tk=tk+604800;
	double n=n0+m_GEPHTemp[satprn].a[5];	//改正的平均角速度;
	double mk=m_GEPHTemp[satprn].a[6]+n*tk;//平近点角;

	double ek1,ek2,ek;									//迭代计算偏近点角ek;
	ek1=mk;					
	do
	{
		ek2=ek1;
		ek1=mk+m_GEPHTemp[satprn].a[8]*sin(ek2);
	}while(fabs(ek1-ek2)>1.0e-12);
	ek=ek1;

	double a,b,fk;										//计算真近点角 fk;
	//double PI=3.141592653589793;
	a=(cos(ek)-m_GEPHTemp[satprn].a[8])/(1-m_GEPHTemp[satprn].a[8]*cos(ek));             //a=cos(fk)
	b=sin(ek)*sqrt(1-m_GEPHTemp[satprn].a[8]*m_GEPHTemp[satprn].a[8])/(1-m_GEPHTemp[satprn].a[8]*cos(ek));//b=sin(fk)
	if(a==0)
		fk=PI/2;
	else if(b==0)
		fk=PI;
	else 
	{
		fk=atan(fabs(b/a));								//第1象限     tan(fk)=b/a=sin(fk)/cos(fk)  
		if(a>0&&b<0)									//第4象限
			fk=2*PI-fk;
		else if(a<0&&b<0)								//第3象限
			fk=PI+fk;
		else if(a<0&&b>0)								//第2象限
			fk=PI-fk;
	}

	double fai_k=fk+m_GEPHTemp[satprn].a[17];					//维度参数;
	double det_uk,det_rk,det_ik;						//周期改正项;
	det_uk=m_GEPHTemp[satprn].a[9]*sin(2*fai_k)+m_GEPHTemp[satprn].a[7]*cos(2*fai_k);
	det_rk=m_GEPHTemp[satprn].a[4]*sin(2*fai_k)+m_GEPHTemp[satprn].a[16]*cos(2*fai_k);
	det_ik=m_GEPHTemp[satprn].a[14]*sin(2*fai_k)+m_GEPHTemp[satprn].a[12]*cos(2*fai_k);

	double uk=fai_k+det_uk;								//改正后的维度参数;
	double rk=A*(1-m_GEPHTemp[satprn].a[8]*cos(ek))+det_rk;	//改正后的向径;
	double ik=m_GEPHTemp[satprn].a[15]+det_ik+m_GEPHTemp[satprn].a[19]*tk;//改正后的倾角;

	double xk,yk,zk;									//卫星在轨道平面中坐标;
	xk=rk*cos(uk);
	yk=rk*sin(uk);
	zk=0;
	double we=7.2921151467e-5;
	if (GNSS_type==1)//GPS系统
	{
		double Lk=m_GEPHTemp[satprn].a[13]+(m_GEPHTemp[satprn].a[18]-we)*tk-we*m_GEPHTemp[satprn].a[11];//观测瞬间升交点的经度值;

		//卫星在地固坐标系中坐标,通过指针传出去;
		*Xk=cos(Lk)*xk-sin(Lk)*cos(ik)*yk+sin(Lk)*sin(ik)*zk;
		*Yk=sin(Lk)*xk+cos(Lk)*cos(ik)*yk-cos(Lk)*sin(ik)*zk;
		*Zk=     0*xk       +sin(ik)*yk       +cos(ik)*zk;
	}
	else if (GNSS_type==2)//BDS系统
	{
		double Lk;
		if (satprn==161||satprn==162||satprn==163||satprn==164||satprn==165)	//GEO卫星位置计算20150805;
		{
			double Xkk,Ykk,Zkk;
			Lk=m_GEPHTemp[satprn].a[13]+m_GEPHTemp[satprn].a[18]*tk-we*m_GEPHTemp[satprn].a[11];			//观测瞬间升交点的经度值;
			Xkk=cos(Lk)*xk-sin(Lk)*cos(ik)*yk+sin(Lk)*sin(ik)*zk;
			Ykk=sin(Lk)*xk+cos(Lk)*cos(ik)*yk-cos(Lk)*sin(ik)*zk;
			Zkk=0*xk+sin(ik)*yk+cos(ik)*zk;

			double n=-PI/36;	//n=-5°
			double alp=we*tk; 
			*Xk= Xkk*cos(alp)+Ykk*sin(alp)*cos(n)+Zkk*sin(alp)*sin(n);
			*Yk=-Xkk*sin(alp)+Ykk*cos(alp)*cos(n)+Zkk*cos(alp)*sin(n);
			*Zk=-sin(n)*Ykk+Zkk*cos(n);
		}
		else
		{
			Lk=m_GEPHTemp[satprn].a[13]+(m_GEPHTemp[satprn].a[18]-we)*tk-we*m_GEPHTemp[satprn].a[11];	//观测瞬间升交点的经度值;						
			*Xk=cos(Lk)*xk-sin(Lk)*cos(ik)*yk+sin(Lk)*sin(ik)*zk;	//卫星在地固坐标系中坐标;		
			*Yk=sin(Lk)*xk+cos(Lk)*cos(ik)*yk-cos(Lk)*sin(ik)*zk;
			*Zk=0*xk+sin(ik)*yk+cos(ik)*zk;
		}
	}


	double e_sinek ;												//RECD relativistic_effect_correction_distence相对论影响距离
	e_sinek=m_GEPHTemp[satprn].a[9]*sin(ek);
	*RECD=-2*m_GEPHTemp[satprn].a[11]*sqrt(GM)*e_sinek/299792458;

	return 0;
}